first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using F9WebAiTest.Application.Common.Exceptions;
|
||||
using F9WebAiTest.Application.Interfaces.SnowflakeID;
|
||||
using F9WebAiTest.Domain.Entities.SYS.RBAC;
|
||||
using F9WebAiTest.Domain.Enums.SYS.RBAC;
|
||||
using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Menus;
|
||||
using MediatR;
|
||||
|
||||
namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Menus.Commands;
|
||||
|
||||
/// <summary>命令定义</summary>
|
||||
public record Menu_CreateCommand(string Name, string IconSvg, MenuType_Enum MenuType, string AssemblyName, string TypeFullName, long ParentId, int SortOrder) : IRequest<long>;
|
||||
|
||||
/// <summary>命令处理器</summary>
|
||||
public class CreateMenuCommandHandler(
|
||||
IMenuWriteRepository menuRepository,
|
||||
ISnowflakeIdGenerator snowflakeIdGenerator,
|
||||
IPublisher eventBus) : IRequestHandler<Menu_CreateCommand, long>
|
||||
{
|
||||
public async Task<long> Handle(Menu_CreateCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(command.Name)) throw new F9OperationException("菜单名称不能为空");
|
||||
|
||||
var menu = new Menu(snowflakeIdGenerator.CreateId(), command.Name, command.IconSvg,
|
||||
command.MenuType, command.AssemblyName, command.TypeFullName, command.ParentId, command.SortOrder);
|
||||
|
||||
var result = await menuRepository.AddAsync(menu);
|
||||
if (result == false) throw new F9OperationException("菜单", "新增");
|
||||
|
||||
foreach (var de in menu.DomainEvents) await eventBus.Publish(de, cancellationToken);
|
||||
menu.ClearDomainEvents();
|
||||
|
||||
return menu.Id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user