package com.huimv.env.admin.controller;


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

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin/menu")
@CrossOrigin
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();
    }
}
