package cn.qinys.platform.upms.api.controller;



import cn.qinys.platform.base.response.Result;
import cn.qinys.platform.base.security.annotation.HasPermission;
import cn.qinys.platform.upms.api.req.*;
import cn.qinys.platform.upms.api.resp.MenuPageResp;
import cn.qinys.platform.upms.api.service.IMenuService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * Description:
 *
 * @author tanlie
 * Date: 2024/2/5 15:36
 */
@RestController
@RequestMapping("/upms/menu")
public class MenuController extends DevBaseController{

    @Resource
    IMenuService menuService;

    /**
     * 菜单列表
     *
     * @return
     */
    @HasPermission({"dev.menu"})
    @GetMapping("/page")
    public Result<List<MenuPageResp>> menuPage() {
        List<MenuPageResp> page = menuService.getMenuPage();
        return new Result<>(page);
    }

    /**
     * 刷新菜单
     *
     * @return
     */
    @GetMapping("/refresh")
    public Result<String> menuRefresh() {
        menuService.refreshMenu();
        return new Result<>("操作成功");
    }

    /**
     * 新增菜单
     *
     * @return
     */
    @HasPermission({"dev.menu"})
    @PostMapping("/create")
    public Result<String> createMenu(@RequestBody @Valid MenuCreateReq req) {
        menuService.createMenu(req);
        return new Result<>("操作成功");
    }

    /**
     * 删除菜单
     *
     * @return
     */
    @HasPermission({"dev.menu"})
    @PostMapping("/remove")
    public Result<String> removeMenu(@RequestBody @Valid MenuRemoveReq req) {
        menuService.removeMenu(req);
        return new Result<>("操作成功");
    }

    /**
     * 更新菜单
     *
     * @return
     */
    @HasPermission({"dev.menu"})
    @PostMapping("/update")
    public Result<String> updateMenu(@RequestBody @Valid MenuUpdateReq req) {
        menuService.updateMenu(req);
        return new Result<>("操作成功");
    }

}
