Skip to content

通过Code查询角色基础信息功能支持#1464

Merged
MayueCif merged 2 commits intomainfrom
feat/get_role_by_code
Jan 23, 2026
Merged

通过Code查询角色基础信息功能支持#1464
MayueCif merged 2 commits intomainfrom
feat/get_role_by_code

Conversation

@MayueCif
Copy link
Contributor

新增RoleBasicDto和RoleDetailByCodeQuery,实现通过角色Code获取基础信息。完善QueryHandler和RoleService相关逻辑,并统一版权声明。

新增RoleBasicDto和RoleDetailByCodeQuery,实现通过角色Code获取基础信息。完善QueryHandler和RoleService相关逻辑,并统一版权声明。
Copilot AI review requested due to automatic review settings January 23, 2026 07:45
移除了RoleBasicDto类中将Name和Code初始化为空字符串的无参构造函数,仅保留带参数的构造函数。此更改有助于避免属性被默认初始化为无意义的空字符串。
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +61 to +66
private async Task<RoleBasicDto> GetDetailByCodeAsync([FromServices] IEventBus eventBus, [FromQuery] string code)
{
var query = new RoleDetailByCodeQuery(code);
await eventBus.PublishAsync(query);
return query.Result;
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +98
.Where(r => r.Code == query.Code)
.FirstOrDefaultAsync();
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
.Where(r => r.Code == query.Code)
.FirstOrDefaultAsync();
.SingleOrDefaultAsync(r => r.Code == query.Code);

Copilot uses AI. Check for mistakes.

namespace Masa.Auth.Service.Admin.Application.Permissions.Queries;

public record RoleDetailByCodeQuery(string Code) : Query<RoleBasicDto>
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
public record RoleDetailByCodeQuery(string Code) : Query<RoleBasicDto>
public record RoleBasicByCodeQuery(string Code) : Query<RoleBasicDto>

Copilot uses AI. Check for mistakes.
@MayueCif MayueCif merged commit 18e7f83 into main Jan 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants