- Replaced instances of the previous messaging system with LiteCqrs across various application components, enhancing the CQRS implementation. - Updated dependency injection to register LiteCqrs services and behaviors, streamlining command and query handling. - Adjusted multiple command and query handlers to align with the new messaging framework, ensuring consistent functionality and improved maintainability. - Added LiteCqrs package reference in the project file for better dependency management.
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using LiteCqrs;
|
|
using PnvPanel.Application.Common.Models;
|
|
using PnvPanel.Domain.Audit;
|
|
|
|
namespace PnvPanel.Application.Admin.Inbounds;
|
|
|
|
public sealed class PublishInboundCommandHandler(IAppDbContext dbContext, ICurrentUser currentUser)
|
|
: ICommandHandler<PublishInboundCommand, Result<InboundDto>>
|
|
{
|
|
public async Task<Result<InboundDto>> Handle(
|
|
PublishInboundCommand command,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var inbound = await dbContext.Inbounds.FirstOrDefaultAsync(
|
|
i => i.Id == command.InboundId,
|
|
cancellationToken
|
|
);
|
|
if (inbound is null)
|
|
return Result.Failure<InboundDto>(InboundErrors.NotFound);
|
|
|
|
if (command.IsPublished)
|
|
inbound.Publish(command.DisplayName, command.AllowedRoleIds);
|
|
else
|
|
inbound.Unpublish();
|
|
|
|
dbContext.AuditLogs.Add(
|
|
AuditLog.Create(
|
|
currentUser.UserId,
|
|
command.IsPublished ? "InboundPublished" : "InboundUnpublished",
|
|
"Inbound",
|
|
inbound.Id.ToString(),
|
|
metadata: null,
|
|
AuditSource.Web
|
|
)
|
|
);
|
|
|
|
return Result.Success(InboundDto.FromDomain(inbound));
|
|
}
|
|
}
|