package com.huimv.eartag2.admin.controller;

import com.huimv.eartag2.admin.entity.Menu;
import com.huimv.eartag2.admin.service.IMenuService;
import com.huimv.eartag2.common.common.token.TokenSign;
import com.huimv.eartag2.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    @PostMapping("/add")
    public Result addMenu(@RequestBody Menu menu , HttpServletRequest request){
        Integer userId = TokenSign.getMemberIdByJwtToken(request);

        return menuService.addMenu(menu,userId);
    }


    @PostMapping("/edit")
    public Result editMenu(@RequestBody Menu menu){
        return menuService.editMenu(menu);
    }


    @RequestMapping("/remove")
    public Result removeMenu(@RequestParam(name = "menuId") Integer menuId){
        return menuService.removeMenu(menuId);
    }

    @PostMapping("/list")
    public Result optimizeList() {
        return menuService.optimizeList();
    }

    @PostMapping("/list1")
    public Result list1() {
        return menuService.list1();
    }
}
