using Microsoft.EntityFrameworkCore; using PnvPanel.Application.Common.Interfaces; using PnvPanel.Application.Common.Messaging; using PnvPanel.Application.Common.Models; namespace PnvPanel.Application.Admin.Inbounds; public sealed class PublishInboundCommandHandler(IAppDbContext dbContext) : 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, command.MaxClients); else inbound.Unpublish(); return Result.Success(InboundDto.FromDomain(inbound)); } }