constellation-api/CH.CQRS/Command/Energy/DisableEnergyProviderCommand.cs

32 lines
985 B
C#
Raw Normal View History

using CH.CQRS.Service.Energy;
using CH.CQRS.Service.Energy.Options;
using FluentValidation;
using OpenHarbor.CQRS.Abstractions;
namespace CH.CQRS.Command.Energy;
public class DisableEnergyProviderCommand
{
public long ProviderId { get; set; }
public DateTime? DisabledAt { get; set; }
}
public class DisableEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler<DisableEnergyProviderCommand>
{
public Task HandleAsync(DisableEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken())
{
return energyService.DisableEnergyProviderAsync(new DisableEnergyProviderCommandOptions
{
ProviderId = command.ProviderId,
DisabledAt = command.DisabledAt,
}, cancellationToken);
}
}
public class DisableEnergyProviderCommandValidator : AbstractValidator<DisableEnergyProviderCommand>
{
public DisableEnergyProviderCommandValidator()
{
RuleFor(command => command.ProviderId)
.NotEmpty();
}
}