- 新建 modules/platform 三层模块(Domain/Application/Infrastructure) - 搬入 8 个实体(User/Role/Permission/UserRole/RolePermission/RefreshToken/Menu/Notification) - 新建 PlatformDbContext(连 platform 库)+ 8 个 EF 配置 + SeedData - 搬入 92 个 Application CQRS 文件 + 57 个 Host Endpoints - RagDbContext 瘦身:只留 RAG 专属表(KnowledgeBase/Document/ChatMessage/Conversation) - Handler 注入改为 PlatformDbContext - appsettings 新增 DatabaseNames:Platform - BuildFlowHostModule 注册 PlatformDbContext + DependsOn PlatformApplicationModule - Conversation 实体去掉 User 导航(跨模块不直接引用实体) - rag SeedData 清空(平台种子归 platform) - 暂移除测 platform 功能的 Rag.Tests(后续建 platform 测试项目) - build 0/0
27 lines
1011 B
C#
27 lines
1011 B
C#
using BuildFlow.Shared.Domain.Exceptions;
|
|
using MediatR;
|
|
using BuildFlow.Platform.Application.Roles.DTOs;
|
|
using BuildFlow.Platform.Domain.Entities;
|
|
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 Role { 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, []);
|
|
}
|
|
}
|