package com.kexue.skills.controller;

import com.kexue.skills.entity.SysUserRole;
import com.kexue.skills.entity.dto.SysUserRoleDto;
import com.kexue.skills.service.SysUserRoleService;
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;

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

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

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