25 lines
948 B
C#
25 lines
948 B
C#
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<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, command.MaxClients);
|
|
else
|
|
inbound.Unpublish();
|
|
|
|
return Result.Success(InboundDto.FromDomain(inbound));
|
|
}
|
|
}
|