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> { public async Task> Handle( PublishInboundCommand command, CancellationToken cancellationToken ) { var inbound = await dbContext.Inbounds.FirstOrDefaultAsync( i => i.Id == command.InboundId, cancellationToken ); if (inbound is null) return Result.Failure(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)); } }