package com.kexue.skills.controller;

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

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

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

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