Conversation
新增RoleBasicDto和RoleDetailByCodeQuery,实现通过角色Code获取基础信息。完善QueryHandler和RoleService相关逻辑,并统一版权声明。
移除了RoleBasicDto类中将Name和Code初始化为空字符串的无参构造函数,仅保留带参数的构造函数。此更改有助于避免属性被默认初始化为无意义的空字符串。
There was a problem hiding this comment.
Pull request overview
该 PR 旨在支持“通过角色 Code 查询角色基础信息”,新增对应的 Query/Handler、DTO,并在 RoleService 中暴露查询入口。
Changes:
- 新增
RoleBasicDto作为按 Code 查询时返回的基础角色模型 - 新增
RoleDetailByCodeQuery及其QueryHandler处理逻辑,实现按 Code 查询角色并返回基础信息 - 在
RoleService中新增按 Code 查询的 REST 入口方法
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Services/Masa.Auth.Service.Admin/Services/RoleService.cs | 增加按 Code 查询角色基础信息的 Service 方法(自动路由映射) |
| src/Services/Masa.Auth.Service.Admin/Application/Permissions/QueryHandler.cs | 增加 RoleDetailByCodeQuery 的事件处理逻辑,从 DB 查询并组装 RoleBasicDto |
| src/Services/Masa.Auth.Service.Admin/Application/Permissions/Queries/RoleDetailByCodeQuery.cs | 新增按 Code 查询的 Query 定义(返回 RoleBasicDto) |
| src/Contracts/Masa.Auth.Contracts.Admin/Permissions/RoleBasicDto.cs | 新增角色基础信息 DTO,用作按 Code 查询的返回模型 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private async Task<RoleBasicDto> GetDetailByCodeAsync([FromServices] IEventBus eventBus, [FromQuery] string code) | ||
| { | ||
| var query = new RoleDetailByCodeQuery(code); | ||
| await eventBus.PublishAsync(query); | ||
| return query.Result; | ||
| } |
There was a problem hiding this comment.
This new endpoint is auto-mapped, but the typed gateway client doesn’t expose it yet (see src/ApiGateways/Masa.Auth.ApiGateways.Caller/Services/Permissions/RoleService.cs, which mirrors the other RoleService endpoints). Add a corresponding caller method (returning RoleBasicDto and taking the code parameter) so Web/Admin and other consumers can call this API without manual URL construction.
| .Where(r => r.Code == query.Code) | ||
| .FirstOrDefaultAsync(); |
There was a problem hiding this comment.
This lookup uses Where(...).FirstOrDefaultAsync(); within this file you also use the predicate overload of FirstOrDefaultAsync elsewhere. Consider switching to the predicate overload for consistency, and (since Add/Update enforce Code uniqueness in Application/Permissions/CommandHandler.cs) consider SingleOrDefaultAsync so duplicate codes don’t silently return an arbitrary role.
| .Where(r => r.Code == query.Code) | |
| .FirstOrDefaultAsync(); | |
| .SingleOrDefaultAsync(r => r.Code == query.Code); |
|
|
||
| namespace Masa.Auth.Service.Admin.Application.Permissions.Queries; | ||
|
|
||
| public record RoleDetailByCodeQuery(string Code) : Query<RoleBasicDto> |
There was a problem hiding this comment.
The query name says “Detail”, but the result type is RoleBasicDto (not RoleDetailDto). Renaming this query (and the corresponding handler/service method) to include “Basic” would make the API intent clearer and reduce the chance of consumers assuming it returns the full role detail model.
| public record RoleDetailByCodeQuery(string Code) : Query<RoleBasicDto> | |
| public record RoleBasicByCodeQuery(string Code) : Query<RoleBasicDto> |
新增RoleBasicDto和RoleDetailByCodeQuery,实现通过角色Code获取基础信息。完善QueryHandler和RoleService相关逻辑,并统一版权声明。