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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.menu.dto.MenuDishesEffectAddDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesEffectEditDTO;
import com.bonus.canteen.core.menu.service.MenuDishesEffectService;
import com.bonus.canteen.core.menu.vo.MenuDishesEffectPageVO;
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/menudisheseffect"})
@Api(
   value = "menudisheseffect",
   tags = {"gyp_菜品功效控制器"}
)
public class MenuDishesEffectController {
   @Autowired
   @Lazy
   private MenuDishesEffectService menuDishesEffectService;

   @PostMapping({"/add"})
   @ApiOperation("新增菜品功效信息")
   public AjaxResult addMenuDishesEffect(@RequestBody @Valid MenuDishesEffectAddDTO dto) {
      this.menuDishesEffectService.addMenuDishesEffect(dto);
      return AjaxResult.success();
   }

   @GetMapping({"/page"})
   @ApiOperation("分页获取菜品功效信息")
   public AjaxResult getMenuDishesEffectPage(String content) {
      Page<MenuDishesEffectPageVO> resultPage = this.menuDishesEffectService.getMenuDishesEffectPage(content);
      return AjaxResult.success(resultPage);
   }

   @PostMapping({"/edit"})
   @ApiOperation("修改菜品功效信息")
   public AjaxResult editMenuDishesEffect(@RequestBody MenuDishesEffectEditDTO dto) {
      this.menuDishesEffectService.editMenuDishesEffect(dto);
      return AjaxResult.success();
   }

   @PostMapping({"/remove/{effectId}"})
   @ApiOperation("删除菜品功效信息")
   public AjaxResult removeByEffectId(@PathVariable Long effectId) {
      this.menuDishesEffectService.removeByEffectId(effectId);
      return AjaxResult.success();
   }
}
