package com.bonus.canteen.core.menu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.menu.dto.MenuDishesTasteAddDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesTasteEditDTO;
import com.bonus.canteen.core.menu.service.MenuDishesTasteService;
import com.bonus.canteen.core.menu.vo.MenuDishesTastePageVO;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping({"/api/v1/menudishestaste"})
@Api(
   value = "menudishestaste",
   tags = {"pfy_菜品口味信息管理"}
)
public class MenuDishesTasteController {
   @Autowired
   @Lazy
   private MenuDishesTasteService menuDishesTasteService;

   @PostMapping({"/add"})
   @ApiOperation("新增菜品口味信息")
   public AjaxResult addMenuDishesTaste(@RequestBody @Valid MenuDishesTasteAddDTO dto) {
      this.menuDishesTasteService.addMenuDishesTaste(dto);
      return AjaxResult.success();
   }

   @GetMapping({"/page"})
   @ApiOperation("分页获取菜品口味信息")
   public AjaxResult getMenuDishesTastePage(String content) {
      Page<MenuDishesTastePageVO> resultPage = this.menuDishesTasteService.getMenuDishesTastePage(content);
      return AjaxResult.success(resultPage);
   }

   @PostMapping({"/edit"})
   @ApiOperation("修改菜品口味信息")
   public AjaxResult editMenuDishesTaste(@RequestBody @Valid MenuDishesTasteEditDTO dto) {
      this.menuDishesTasteService.editMenuDishesTaste(dto);
      return AjaxResult.success();
   }

   @PostMapping({"/remove/{tasteId}"})
   @ApiOperation("删除菜品口味信息")
   public AjaxResult removeByTasteId(@PathVariable Long tasteId) {
      this.menuDishesTasteService.removeByTasteId(tasteId);
      return AjaxResult.success();
   }
}
