Conversation
RoleSelectDto 类新增 CreationTime(创建时间)属性,移除无参构造函数,所有相关构造函数调用均需传入 CreationTime。同步调整 User.cs 和 QueryHandler.cs 中 RoleModel 及 RoleSelectDto 的创建逻辑,确保角色信息包含创建时间,便于前端展示和业务处理。
- 移除 RoleSelectDto 的 CreationTime 属性及相关参数,简化角色选择数据结构
- 新增 UserRoleDto 类,支持用户角色信息(编码、名称、绑定时间)
- 新增 UserRolesQuery 查询对象,实现按用户ID查询角色列表
- QueryHandler 增加 GetUserRolesAsync 方法,完善角色查询逻辑
- UserService 新增 GetUserRolesAsync 接口,路由为 /{id}/roles
- 补充部分文件的 Apache License 版权声明
- 提升用户角色相关功能的规范性和可维护性
新增RoleSelectDto.CreationTime属性,并调整相关构造函数参数。同步更新QueryHandler中所有RoleSelectDto的创建逻辑,确保传递CreationTime字段,以便角色信息包含创建时间。
There was a problem hiding this comment.
Pull request overview
This pull request adds a new API endpoint to retrieve user roles for a specific user. The main feature adds GET /api/user/{id}/roles endpoint that returns a list of enabled roles associated with a user, including role code, name, and the binding time. However, the PR has critical compilation issues due to a missing type definition.
Changes:
- Added new GET endpoint
/api/user/{id}/rolesto retrieve user roles by user ID - Added query handler
GetUserRolesAsyncand query classUserRolesQueryto support the new endpoint - Enhanced
RoleModelmapping inUser.csto include additional properties (CreationTime, ModificationTime, Enabled) - Added enabled role filtering to
GetRoleSelectAsyncmethod - Removed parameterless constructor from
RoleSelectDto - Minor code formatting improvements
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Services/Masa.Auth.Service.Admin/Services/UserService.cs | Adds new MapGet route for getting user roles endpoint |
| src/Services/Masa.Auth.Service.Admin/Application/Subjects/QueryHandler.cs | Implements GetUserRolesAsync query handler to fetch enabled roles for a user |
| src/Services/Masa.Auth.Service.Admin/Application/Subjects/Queries/UserRolesQuery.cs | Defines new query class for user roles retrieval |
| src/Services/Masa.Auth.Service.Admin/Application/Permissions/QueryHandler.cs | Adds filtering for enabled roles in GetRoleSelectAsync helper method |
| src/Domain/Masa.Auth.Domain/Subjects/Aggregates/User.cs | Enriches RoleModel with CreationTime, ModificationTime, and Enabled properties |
| src/Contracts/Masa.Auth.Contracts.Admin/Permissions/RoleSelectDto.cs | Removes parameterless constructor |
Comments suppressed due to low confidence (1)
src/Contracts/Masa.Auth.Contracts.Admin/Permissions/RoleSelectDto.cs:26
- Removing the parameterless constructor may cause issues with serialization/deserialization in certain scenarios and breaks consistency with similar DTOs in the codebase (e.g., UserSelectDto in src/Contracts/Masa.Auth.Contracts.Admin/Subjects/UserSelectDto.cs:22). The Name and Code properties are non-nullable strings but are no longer initialized to empty strings when a parameterless constructor would be used. Consider keeping the parameterless constructor for compatibility, or verify that all serialization scenarios work correctly without it.
public RoleSelectDto(Guid id, string name, string code, int limit, int availableQuantity)
{
Id = id;
Name = name;
Code = code;
Limit = limit;
AvailableQuantity = availableQuantity;
CreationTime = creationTime;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
|
||
| namespace Masa.Auth.Service.Admin.Application.Subjects.Queries; | ||
|
|
There was a problem hiding this comment.
The UserRoleModel type does not exist in the codebase. This query definition will cause compilation errors. You need to either:
- Create a UserRoleModel class/record in the appropriate location (e.g., in src/Contracts/Masa.Auth.Contracts.Admin/Subjects/), or
- Use an existing type like RoleModel or RoleSelectDto
Based on the query handler implementation that uses Code, Name, and BindTime properties, you should create a new UserRoleModel with these properties.
| public record UserRoleModel(string Code, string Name, DateTime BindTime); |
| .Select(ur => new UserRoleModel | ||
| { | ||
| Code = ur.Role.Code, | ||
| Name = ur.Role.Name, | ||
| BindTime = ur.CreationTime | ||
| }) |
There was a problem hiding this comment.
The UserRoleModel type does not exist in the codebase, which will cause compilation errors. The query handler attempts to create instances of UserRoleModel with Code, Name, and BindTime properties, but this type is not defined anywhere in the repository or imported from external packages.
| return query.Result; | ||
| } | ||
|
|
||
| public async Task<List<UserRoleModel>> GetUserRolesAsync(IEventBus eventBus, Guid id) |
There was a problem hiding this comment.
The UserRoleModel return type does not exist in the codebase, which will cause compilation errors. This endpoint cannot function until the UserRoleModel class/record is defined with the appropriate properties (Code, Name, BindTime based on the query handler implementation).
| Code = ur.Role.Code, | ||
| Name = ur.Role.Name, | ||
| BindTime = ur.CreationTime |
There was a problem hiding this comment.
Potential null reference exception when accessing ur.Role properties. The Where clause filters for ur.Role.Enabled, but if ur.Role is null at the time of Select, this will throw a NullReferenceException. Consider adding an additional null check in the Where clause or using null-conditional operators in the Select clause to make the code more defensive.
| MapGet(GetListByRoleAsync, "getListByRole"); | ||
| MapGet(GetUserRolesAsync, "{id}/roles"); | ||
| MapGet(GetClaimValuesAsync, "claim-values/{id}"); | ||
| MapGet(GetClaimValuesAsync, "claim-values"); |
There was a problem hiding this comment.
Call to obsolete method MapGet.
| MapGet(GetListByRoleAsync, "getListByRole"); | |
| MapGet(GetUserRolesAsync, "{id}/roles"); | |
| MapGet(GetClaimValuesAsync, "claim-values/{id}"); | |
| MapGet(GetClaimValuesAsync, "claim-values"); | |
| MapGet("getListByRole", GetListByRoleAsync); | |
| MapGet("{id}/roles", GetUserRolesAsync); | |
| MapGet("claim-values/{id}", GetClaimValuesAsync); | |
| MapGet("claim-values", GetClaimValuesAsync); |
增加获取用户角色的接口