- 从多个文件中移除未使用的 System.Linq.Dynamic.Core 引用 - 从多个文件中移除未使用的 Microsoft.EntityFrameworkCore 引用 - 从 IM 模块中移除未使用的 MongoDB.Driver.Linq 引用 - 清理 Handler 文件中的冗余命名空间引用 - 优化代码结构减少不必要的依赖引入 - 提高代码整洁性和编译效率
25 lines
929 B
C#
25 lines
929 B
C#
using BuildFlow.Shared.Domain.Exceptions;
|
|
using MediatR;
|
|
using BuildFlow.Application.Roles.DTOs;
|
|
using BuildFlow.Infrastructure.Persistence;
|
|
using BuildFlow.Application.Roles.Queries;
|
|
|
|
namespace BuildFlow.Application.Roles.Handlers;
|
|
|
|
/// <summary>
|
|
/// Get角色ById查询处理器。执行业务校验后持久化。
|
|
/// </summary>
|
|
public class GetRoleByIdQueryHandler(RagDbContext db) : IRequestHandler<GetRoleByIdQuery, RoleDto>
|
|
{
|
|
public async Task<RoleDto> Handle(GetRoleByIdQuery request, CancellationToken ct)
|
|
{
|
|
var role = await db.Roles
|
|
.Include(r => r.RolePermissions).ThenInclude(rp => rp.Permission)
|
|
.FirstOrDefaultAsync(r => r.Id == request.Id, ct)
|
|
?? throw new NotFoundException("角色不存在");
|
|
|
|
return new RoleDto(role.Id, role.Name, role.Description, role.CreatedAt,
|
|
role.RolePermissions.Select(rp => rp.Permission.Code).ToList());
|
|
}
|
|
}
|