package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.domain.Menu;
import com.tuoheng.admin.entity.query.MenuQuery;
import com.tuoheng.admin.service.system.menu.IMenuService;
import com.tuoheng.common.core.annotation.Log;
import com.tuoheng.common.core.enums.LogType;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序菜单表 前端控制器
 *
 * @Author ChengWang
 * @Date 2022/12/23
 */
@RestController
@RequestMapping("/apiMenu")
public class ApiMenuController {

    @Autowired
    private IMenuService menuService;

    /**
     * 获取菜单列表
     * @param menuQuery
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(MenuQuery menuQuery){
        return menuService.getList(menuQuery);
    }

    /**
     * 获取菜单详情
     * @param menuId
     * @return
     */
    @GetMapping("/info/{menuId}")
    public JsonResult info(@PathVariable("menuId") Integer menuId) {
        return menuService.info(menuId);
    }

    /**
     * 添加菜单
     *
     * @param entity 实体对象
     * @return
     */
    @Log(title = "菜单管理", logType = LogType.INSERT)
    @PostMapping("/add")
    public JsonResult add(@RequestBody Menu entity) {
        return menuService.edit(entity);
    }

    /**
     * 编辑菜单
     *
     * @param entity 实体对象
     * @return
     */
    @Log(title = "菜单管理", logType = LogType.UPDATE)
//    @RequiresPermissions("sys:menu:edit")
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody Menu entity) {
        return menuService.edit(entity);
    }

    /**
     * 删除菜单
     *
     * @param menuId 菜单ID
     * @return
     */
    @Log(title = "菜单管理", logType = LogType.DELETE)
//    @RequiresPermissions("sys:menu:delete")
    @DeleteMapping("/delete/{menuId}")
    public JsonResult delete(@PathVariable("menuId") Integer menuId) {
        return menuService.deleteById(menuId);
    }

    /**
     * 获取所有菜单列表
     *
     * @return
     */
    @GetMapping("/getMenuAll")
    public JsonResult getMenuAll() {
        List<Menu> menuList = menuService.getMenuAll();
        return JsonResult.success(menuList);
    }




}
