feat(role): 新增获取用户角色接口
- 在RoleController中新增getUserRole方法,用于获取所有用户角色 - 添加RoleService接口及其实现类RoleServiceImpl - 创建RoleResponse DTO并优化UserProfileResponse中的角色映射逻辑 - 引入RoleService依赖并配置相关注解以支持新功能 - 实现角色数据的查询与转换,返回标准ApiResult格式结果
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
package cn.nopj.chaos_api.dto.response;
|
||||
|
||||
import cn.nopj.chaos_api.domain.entity.Role;
|
||||
import lombok.Data;
|
||||
@Data
|
||||
public class RoleResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
|
||||
public RoleResponse(Role role){
|
||||
this.id = role.getId();
|
||||
this.name = role.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,17 +10,14 @@ public class UserProfileResponse {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String nickname;
|
||||
private String avatar;
|
||||
private List<RoleResponse> roles;
|
||||
|
||||
public UserProfileResponse(User user) {
|
||||
this.id = user.getId();
|
||||
this.username = user.getUsername();
|
||||
this.nickname = user.getNickname();
|
||||
this.roles = user.getRoles().stream().map(role -> {
|
||||
RoleResponse roleResponse = new RoleResponse();
|
||||
roleResponse.setId(role.getId());
|
||||
roleResponse.setName(role.getName());
|
||||
return roleResponse;
|
||||
}).toList();
|
||||
this.avatar = user.getAvatar();
|
||||
this.roles = user.getRoles().stream().map(RoleResponse::new).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user