package com.kexue.skills.controller;

import com.kexue.skills.entity.SysMenu;
import com.kexue.skills.entity.dto.SysMenuDto;
import com.kexue.skills.service.SysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.github.pagehelper.PageInfo;
import com.kexue.skills.common.CommonResult;
import com.kexue.skills.entity.base.IdDto;

/**
 * (SysMenu)表控制层
 *
 * @author 王志维
 * @since 2025-02-21 23:01:48
 */
@RestController
@RequestMapping("api/sysMenu")
@Tag(name = "系统菜单 Api")
@CrossOrigin(origins = "*")
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysMenuService sysMenuService;
    /**
     * 分页查询
     *
     * @param queryDto 筛选条件
     * @return 查询结果
     */
    @PostMapping("/getPageList")
    @Operation(summary = "查询分页列表",description = "查询分页列表")
    public CommonResult<PageInfo<SysMenu>> getPageList(@RequestBody SysMenuDto queryDto) {
        return CommonResult.success(sysMenuService.getPageList(queryDto));
    }
    
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("queryById/{id}")
    @Operation(summary = "通过ID查询菜单", description = "通过ID查询菜单")
    public CommonResult<SysMenu> queryById(@PathVariable("id") Long id) {
        return CommonResult.success(sysMenuService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param SysMenu 实体
     * @return 新增结果
     */
    @PostMapping("/insert")
    @Operation(summary = "新增菜单", description = "新增菜单")
    public CommonResult<SysMenu> insert(@RequestBody SysMenu SysMenu) {
        return CommonResult.success(sysMenuService.insert(SysMenu));
    }

    /**
     * 编辑数据
     *
     * @param SysMenu 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    @Operation(summary = "更新菜单", description = "更新菜单")
    public CommonResult<SysMenu> update(@RequestBody SysMenu SysMenu) {
        return CommonResult.success(sysMenuService.update(SysMenu));
    }
    
    /**
     * 删除数据
     *
     * @param id
     * @return 删除数据
     */
    @PostMapping("deleteById/{id}")
    @Operation(summary = "删除菜单", description = "删除菜单")
    public CommonResult<Boolean> deleteById(@PathVariable("id") Long id) {
        return CommonResult.success(sysMenuService.deleteById(id));
    }
}
