- 从文件模块的多部分上传处理器中移除未使用的实体引用 - 从即时通讯模块的群组成员处理器中移除未使用的实体引用 - 从RAG模块的AI模型配置中移除未使用的实体引用 - 从监控模块的告警规则配置中移除未使用的实体引用 - 从平台模块的角色权限处理器中移除未使用的实体引用 - 从脚本模块的执行日志实体引用中进行清理 - 从多个基础设施配置类中移除未使用的依赖项 - 优化测试文件中的导入声明,移除不必要的引用
27 lines
1022 B
C#
27 lines
1022 B
C#
using BuildFlow.Shared.Domain.Exceptions;
|
|
using MediatR;
|
|
using BuildFlow.Platform.Application.Roles.DTOs;
|
|
using BuildFlow.Platform.Domain.Entities.Role;
|
|
using BuildFlow.Platform.Infrastructure.Persistence;
|
|
using BuildFlow.Platform.Application.Roles.Commands;
|
|
|
|
namespace BuildFlow.Platform.Application.Roles.Handlers;
|
|
|
|
/// <summary>
|
|
/// Create角色Command处理器。执行业务校验后持久化。
|
|
/// </summary>
|
|
public class CreateRoleCommandHandler(PlatformDbContext db) : IRequestHandler<CreateRoleCommand, RoleDto>
|
|
{
|
|
public async Task<RoleDto> Handle(CreateRoleCommand request, CancellationToken ct)
|
|
{
|
|
if (await db.Roles.AnyAsync(r => r.Name == request.Name, ct))
|
|
throw new BusinessException("角色名已存在");
|
|
|
|
var role = new RoleEntity { Name = request.Name, Description = request.Description };
|
|
await db.Roles.AddAsync(role, ct);
|
|
await db.SaveChangesAsync(ct);
|
|
|
|
return new RoleDto(role.Id, role.Name, role.Description, role.CreatedAt, []);
|
|
}
|
|
}
|