add currency in update command

This commit is contained in:
DavidGudEnough 2025-01-22 18:11:25 -05:00
parent ef674cefea
commit 0ba2e45b38
Signed by: david.nguyen
GPG Key ID: 0B95DC36355BEB37
3 changed files with 9 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using CH.CQRS.Service.Energy.Options;
using CH.Dal; using CH.Dal;
using CH.Dal.DbEntity; using CH.Dal.DbEntity;
using CH.Dal.Validators; using CH.Dal.Validators;
using CH.Enum;
using FluentValidation; using FluentValidation;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using OpenHarbor.CQRS.Abstractions; using OpenHarbor.CQRS.Abstractions;
@ -16,6 +17,7 @@ public class UpdateEnergyRateCommand
public string? Name { get; set; } public string? Name { get; set; }
public DateTime? StartedAt { get; set; } public DateTime? StartedAt { get; set; }
public decimal? Rate { get; set; } public decimal? Rate { get; set; }
public Currency Currency { get; set; }
} }
public class UpdateEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler<UpdateEnergyRateCommand> public class UpdateEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler<UpdateEnergyRateCommand>
{ {
@ -26,7 +28,8 @@ public class UpdateEnergyRateCommandHandler(EnergyService energyService) : IComm
RateId = command.RateId, RateId = command.RateId,
Name = command.Name, Name = command.Name,
StartedAt = command.StartedAt, StartedAt = command.StartedAt,
Rate = command.Rate Rate = command.Rate,
Currency = command.Currency
}, cancellationToken); }, cancellationToken);
} }
} }

View File

@ -83,10 +83,11 @@ public class EnergyService(CHDbContext dbContext)
if (options.Rate.HasValue) if (options.Rate.HasValue)
energyRate.Rate = options.Rate.Value; energyRate.Rate = options.Rate.Value;
if (false == string.IsNullOrWhiteSpace(options.Name)) if (false == string.IsNullOrWhiteSpace(options.Name))
energyRate.Name = options.Name; energyRate.Name = options.Name;
energyRate.Currency = options.Currency;
energyRate.UpdatedAt = DateTime.UtcNow; energyRate.UpdatedAt = DateTime.UtcNow;
} }
public async Task UpdateEnergyRateAsync(UpdateEnergyRateCommandOptions options, CancellationToken cancellationToken) public async Task UpdateEnergyRateAsync(UpdateEnergyRateCommandOptions options, CancellationToken cancellationToken)

View File

@ -1,3 +1,5 @@
using CH.Enum;
namespace CH.CQRS.Service.Energy.Options; namespace CH.CQRS.Service.Energy.Options;
public class UpdateEnergyRateCommandOptions public class UpdateEnergyRateCommandOptions
@ -6,4 +8,5 @@ public class UpdateEnergyRateCommandOptions
public DateTime? StartedAt { get; set; } public DateTime? StartedAt { get; set; }
public decimal? Rate { get; set; } public decimal? Rate { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public Currency Currency { get; set; }
} }