feat(role): 新增获取用户角色接口
- 在RoleController中新增getUserRole方法,用于获取所有用户角色 - 添加RoleService接口及其实现类RoleServiceImpl - 创建RoleResponse DTO并优化UserProfileResponse中的角色映射逻辑 - 引入RoleService依赖并配置相关注解以支持新功能 - 实现角色数据的查询与转换,返回标准ApiResult格式结果
This commit is contained in:
@@ -2,16 +2,21 @@ package cn.nopj.chaos_api.controller;
|
||||
|
||||
|
||||
import cn.nopj.chaos_api.dto.request.SetUserRoleRequest;
|
||||
import cn.nopj.chaos_api.dto.response.RoleResponse;
|
||||
import cn.nopj.chaos_api.model.ApiResult;
|
||||
import cn.nopj.chaos_api.service.RoleService;
|
||||
import cn.nopj.chaos_api.service.UserRoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 角色管理
|
||||
@@ -24,6 +29,9 @@ public class RoleController {
|
||||
@Autowired
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
/**
|
||||
* 设置用户角色
|
||||
* @param request 请求参数
|
||||
@@ -45,4 +53,13 @@ public class RoleController {
|
||||
public ApiResult<?> revokeRolesFromUser(@RequestBody @Validated SetUserRoleRequest request) {
|
||||
return ApiResult.success("用户角色取消成功",userRoleService.revokeRolesFromUser(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户角色
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('admin')")
|
||||
@GetMapping("/")
|
||||
public ApiResult<List<RoleResponse>> getUserRole() {
|
||||
return ApiResult.success(roleService.getAllRoles());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user