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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.menu.dto.MenuDishesSuitAddDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesSuitEditDTO;
import com.bonus.canteen.core.menu.service.MenuDishesSuitService;
import com.bonus.canteen.core.menu.vo.MenuDishesSuitPageVO;
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/menudishessuit"})
@Api(
   value = "menudishessuit",
   tags = {"gyp_适宜人群控制器"}
)
public class MenuDishesSuitController {
   @Autowired
   @Lazy
   private MenuDishesSuitService menuDishesSuitService;

   @PostMapping({"/add"})
   @ApiOperation("新增适宜人群信息")
   public AjaxResult addMenuDishesSuit(@RequestBody @Valid MenuDishesSuitAddDTO dto) {
      this.menuDishesSuitService.addMenuDishesSuit(dto);
      return AjaxResult.success();
   }

   @GetMapping({"/page"})
   @ApiOperation("分页获取适宜人群信息")
   public AjaxResult getMenuDishesSuitPage(String content) {
      Page<MenuDishesSuitPageVO> resultPage = this.menuDishesSuitService.getMenuDishesSuitPage(content);
      return AjaxResult.success(resultPage);
   }

   @PostMapping({"/edit"})
   @ApiOperation("修改适宜人群信息")
   public AjaxResult editMenuDishesSuit(@RequestBody MenuDishesSuitEditDTO dto) {
      this.menuDishesSuitService.editMenuDishesSuit(dto);
      return AjaxResult.success();
   }

   @PostMapping({"/remove/{suitId}"})
   @ApiOperation("删除适宜人群信息")
   public AjaxResult removeBySuitId(@PathVariable Long suitId) {
      this.menuDishesSuitService.removeBySuitId(suitId);
      return AjaxResult.success();
   }
}
