2025-01-10 15:59:51 -05:00
|
|
|
using CH.CQRS.Service.Energy;
|
|
|
|
using CH.CQRS.Service.Energy.Options;
|
|
|
|
using FluentValidation;
|
|
|
|
using OpenHarbor.CQRS.Abstractions;
|
|
|
|
|
2025-01-09 16:14:34 -05:00
|
|
|
namespace CH.CQRS.Command.Energy;
|
|
|
|
|
|
|
|
public class CreateEnergyRateExceptionCommand
|
|
|
|
{
|
2025-01-10 15:59:51 -05:00
|
|
|
public long RateId { get; set; }
|
|
|
|
public required string Name { get; set; }
|
|
|
|
public decimal EnergyThreshold { get; set; }
|
|
|
|
public string? ResetType { get; set; }
|
|
|
|
public DateTime? StartedAt { get; set; }
|
|
|
|
public DateTime? EndedAt { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CreateEnergyRateExceptionCommandHandler(EnergyService energyService) : ICommandHandler<CreateEnergyRateExceptionCommand>
|
|
|
|
{
|
|
|
|
public Task HandleAsync(CreateEnergyRateExceptionCommand command,
|
|
|
|
CancellationToken cancellationToken = new CancellationToken())
|
|
|
|
{
|
|
|
|
return energyService.CreateEnergyRateExceptionAsync(new CreateEnergyRateExceptionCommandOptions
|
|
|
|
{
|
|
|
|
RateId = command.RateId,
|
|
|
|
Name = command.Name,
|
|
|
|
EnergyThreshold = command.EnergyThreshold,
|
|
|
|
ResetType = command.ResetType,
|
|
|
|
StartedAt = command.StartedAt,
|
|
|
|
EndedAt = command.EndedAt
|
|
|
|
}, cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class CreateEnergyRateExceptionCommandValidator : AbstractValidator<CreateEnergyRateExceptionCommand>
|
|
|
|
{
|
|
|
|
public CreateEnergyRateExceptionCommandValidator()
|
|
|
|
{
|
|
|
|
RuleFor(command => command.EnergyThreshold)
|
|
|
|
.GreaterThan(0);
|
|
|
|
RuleFor(command => command.RateId)
|
|
|
|
.NotEmpty();
|
|
|
|
}
|
2025-01-09 16:14:34 -05:00
|
|
|
}
|