From ef674cefea1817804819837ab114927ffd7fac23 Mon Sep 17 00:00:00 2001 From: DavidGudEnough Date: Tue, 21 Jan 2025 17:58:20 -0500 Subject: [PATCH] change command name from create to add --- ...erCommand.cs => AddEnergyProviderCommand.cs} | 12 ++++++------ ...gyRateCommand.cs => AddEnergyRateCommand.cs} | 12 ++++++------ ...mand.cs => AddEnergyRateExceptionCommand.cs} | 12 ++++++------ .../Energy/ServiceCollectionExtension.cs | 12 ++++++------ CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs | 17 ++++++++++++----- .../Query/CryptoStat/CryptoStatQueryResult.cs | 8 ++++++++ CH.CQRS/QueryModule.cs | 2 +- CH.CQRS/Service/Energy/EnergyService.cs | 6 +++--- ...ns.cs => AddEnergyProviderCommandOptions.cs} | 2 +- ...ptions.cs => AddEnergyRateCommandOptions.cs} | 2 +- ... => AddEnergyRateExceptionCommandOptions.cs} | 2 +- 11 files changed, 51 insertions(+), 36 deletions(-) rename CH.CQRS/Command/Energy/{CreateEnergyProviderCommand.cs => AddEnergyProviderCommand.cs} (60%) rename CH.CQRS/Command/Energy/{CreateEnergyRateCommand.cs => AddEnergyRateCommand.cs} (72%) rename CH.CQRS/Command/Energy/{CreateEnergyRateExceptionCommand.cs => AddEnergyRateExceptionCommand.cs} (74%) create mode 100644 CH.CQRS/Query/CryptoStat/CryptoStatQueryResult.cs rename CH.CQRS/Service/Energy/Options/{CreateEnergyProviderCommandOptions.cs => AddEnergyProviderCommandOptions.cs} (72%) rename CH.CQRS/Service/Energy/Options/{CreateEnergyRateCommandOptions.cs => AddEnergyRateCommandOptions.cs} (87%) rename CH.CQRS/Service/Energy/Options/{CreateEnergyRateExceptionCommandOptions.cs => AddEnergyRateExceptionCommandOptions.cs} (86%) diff --git a/CH.CQRS/Command/Energy/CreateEnergyProviderCommand.cs b/CH.CQRS/Command/Energy/AddEnergyProviderCommand.cs similarity index 60% rename from CH.CQRS/Command/Energy/CreateEnergyProviderCommand.cs rename to CH.CQRS/Command/Energy/AddEnergyProviderCommand.cs index 55aeabb..5cd4398 100644 --- a/CH.CQRS/Command/Energy/CreateEnergyProviderCommand.cs +++ b/CH.CQRS/Command/Energy/AddEnergyProviderCommand.cs @@ -9,16 +9,16 @@ using OpenHarbor.CQRS.Abstractions; namespace CH.CQRS.Command.Energy; -public class CreateEnergyProviderCommand +public class AddEnergyProviderCommand { public required string Name { get; set; } public bool Active { get; set; } } -public class CreateEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler +public class AddEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler { - public Task HandleAsync(CreateEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken()) + public Task HandleAsync(AddEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken()) { - return energyService.CreateEnergyProviderAsync(new CreateEnergyProviderCommandOptions + return energyService.CreateEnergyProviderAsync(new AddEnergyProviderCommandOptions { Name = command.Name, Active = command.Active @@ -26,9 +26,9 @@ public class CreateEnergyProviderCommandHandler(EnergyService energyService) : I } } -public class CreateEnergyProviderCommandValidator : AbstractValidator +public class AddEnergyProviderCommandValidator : AbstractValidator { - public CreateEnergyProviderCommandValidator(CHDbContext dbContext) + public AddEnergyProviderCommandValidator(CHDbContext dbContext) { RuleFor(command => command.Name) .NotEmpty() diff --git a/CH.CQRS/Command/Energy/CreateEnergyRateCommand.cs b/CH.CQRS/Command/Energy/AddEnergyRateCommand.cs similarity index 72% rename from CH.CQRS/Command/Energy/CreateEnergyRateCommand.cs rename to CH.CQRS/Command/Energy/AddEnergyRateCommand.cs index 8a3d6da..0bdc70c 100644 --- a/CH.CQRS/Command/Energy/CreateEnergyRateCommand.cs +++ b/CH.CQRS/Command/Energy/AddEnergyRateCommand.cs @@ -10,7 +10,7 @@ using OpenHarbor.CQRS.Abstractions; namespace CH.CQRS.Command.Energy; -public class CreateEnergyRateCommand +public class AddEnergyRateCommand { public long ProviderId { get; set; } public required string Name { get; set; } @@ -18,11 +18,11 @@ public class CreateEnergyRateCommand public Currency Currency { get; set; } public bool Active { get; set; } } -public class CreateEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler +public class AddEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler { - public Task HandleAsync(CreateEnergyRateCommand command, CancellationToken cancellationToken = new CancellationToken()) + public Task HandleAsync(AddEnergyRateCommand command, CancellationToken cancellationToken = new CancellationToken()) { - return energyService.CreateEnergyRateAsync(new CreateEnergyRateCommandOptions + return energyService.CreateEnergyRateAsync(new AddEnergyRateCommandOptions { ProviderId = command.ProviderId, Name = command.Name, @@ -33,9 +33,9 @@ public class CreateEnergyRateCommandHandler(EnergyService energyService) : IComm } } -public class CreateEnergyRateCommandValidator : AbstractValidator +public class AddEnergyRateCommandValidator : AbstractValidator { - public CreateEnergyRateCommandValidator(CHDbContext dbContext) + public AddEnergyRateCommandValidator(CHDbContext dbContext) { RuleFor(command => command.Name) .NotEmpty() diff --git a/CH.CQRS/Command/Energy/CreateEnergyRateExceptionCommand.cs b/CH.CQRS/Command/Energy/AddEnergyRateExceptionCommand.cs similarity index 74% rename from CH.CQRS/Command/Energy/CreateEnergyRateExceptionCommand.cs rename to CH.CQRS/Command/Energy/AddEnergyRateExceptionCommand.cs index 551bd14..1c8cb35 100644 --- a/CH.CQRS/Command/Energy/CreateEnergyRateExceptionCommand.cs +++ b/CH.CQRS/Command/Energy/AddEnergyRateExceptionCommand.cs @@ -10,7 +10,7 @@ using OpenHarbor.CQRS.Abstractions; namespace CH.CQRS.Command.Energy; -public class CreateEnergyRateExceptionCommand +public class AddEnergyRateExceptionCommand { public long RateId { get; set; } public required string Name { get; set; } @@ -20,12 +20,12 @@ public class CreateEnergyRateExceptionCommand public DateTime? EndedAt { get; set; } } -public class CreateEnergyRateExceptionCommandHandler(EnergyService energyService) : ICommandHandler +public class AddEnergyRateExceptionCommandHandler(EnergyService energyService) : ICommandHandler { - public Task HandleAsync(CreateEnergyRateExceptionCommand command, + public Task HandleAsync(AddEnergyRateExceptionCommand command, CancellationToken cancellationToken = new CancellationToken()) { - return energyService.CreateEnergyRateExceptionAsync(new CreateEnergyRateExceptionCommandOptions + return energyService.AddEnergyRateExceptionAsync(new AddEnergyRateExceptionCommandOptions { RateId = command.RateId, Name = command.Name, @@ -36,9 +36,9 @@ public class CreateEnergyRateExceptionCommandHandler(EnergyService energyService }, cancellationToken); } } -public class CreateEnergyRateExceptionCommandValidator : AbstractValidator +public class AddEnergyRateExceptionCommandValidator : AbstractValidator { - public CreateEnergyRateExceptionCommandValidator(CHDbContext dbContext) + public AddEnergyRateExceptionCommandValidator(CHDbContext dbContext) { RuleFor(command => command.Name) .NotEmpty() diff --git a/CH.CQRS/Command/Energy/ServiceCollectionExtension.cs b/CH.CQRS/Command/Energy/ServiceCollectionExtension.cs index 69e031c..a7baec2 100644 --- a/CH.CQRS/Command/Energy/ServiceCollectionExtension.cs +++ b/CH.CQRS/Command/Energy/ServiceCollectionExtension.cs @@ -8,14 +8,14 @@ public static class ServiceCollectionExtension public static IServiceCollection AddEnergyCommand(this IServiceCollection services) { services - .AddCommand(); + .AddCommand(); services - .AddCommand(); + .AddCommand(); services - .AddCommand(); + .AddCommand(); services .AddCommand(); diff --git a/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs b/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs index 154207b..05924d8 100644 --- a/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs +++ b/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs @@ -6,13 +6,20 @@ namespace CH.CQRS.Query.CryptoStat; public class CryptoStatQuery { - public required string CoinName { get; set; } - public required string Currency { get; set; } + // public required string CoinName { get; set; } + // public required string Currency { get; set; } } -public class CryptoStatQueryHandler(CoinMarketCapService coinMarketCapService) : IQueryHandler +public class CryptoStatQueryHandler(CoinMarketCapService coinMarketCapService) : IQueryHandler { - public Task HandleAsync(CryptoStatQuery query, CancellationToken cancellationToken = new CancellationToken()) + public async Task HandleAsync(CryptoStatQuery query, CancellationToken cancellationToken = new CancellationToken()) { - return coinMarketCapService.GetCryptoStatsAsync(query.CoinName, query.Currency, cancellationToken); + var listCrypto = new List(); + var cryptoStats = await coinMarketCapService.GetCryptoStatsAsync("bitcoin", "cad", cancellationToken); + listCrypto.Add(cryptoStats); + var listStat = new CryptoStatQueryResult + { + Data = listCrypto + }; + return listStat; } } \ No newline at end of file diff --git a/CH.CQRS/Query/CryptoStat/CryptoStatQueryResult.cs b/CH.CQRS/Query/CryptoStat/CryptoStatQueryResult.cs new file mode 100644 index 0000000..c573a0c --- /dev/null +++ b/CH.CQRS/Query/CryptoStat/CryptoStatQueryResult.cs @@ -0,0 +1,8 @@ +using Microsoft.EntityFrameworkCore.Diagnostics; + +namespace CH.CQRS.Query.CryptoStat; + +public class CryptoStatQueryResult +{ + public required List Data { get; set; } +} \ No newline at end of file diff --git a/CH.CQRS/QueryModule.cs b/CH.CQRS/QueryModule.cs index f416bb6..ba2e8ea 100644 --- a/CH.CQRS/QueryModule.cs +++ b/CH.CQRS/QueryModule.cs @@ -21,7 +21,7 @@ public class QueryModule : IModule services.AddQuery(); services.AddQuery(); services.AddQuery(); - services.AddQuery(); + services.AddQuery(); return services; } } diff --git a/CH.CQRS/Service/Energy/EnergyService.cs b/CH.CQRS/Service/Energy/EnergyService.cs index a8bc471..0c5568d 100644 --- a/CH.CQRS/Service/Energy/EnergyService.cs +++ b/CH.CQRS/Service/Energy/EnergyService.cs @@ -9,7 +9,7 @@ namespace CH.CQRS.Service.Energy; public class EnergyService(CHDbContext dbContext) { - public async Task CreateEnergyProviderAsync(CreateEnergyProviderCommandOptions options, CancellationToken cancellationToken) + public async Task CreateEnergyProviderAsync(AddEnergyProviderCommandOptions options, CancellationToken cancellationToken) { var energyProvider = new EnergyProvider { @@ -22,7 +22,7 @@ public class EnergyService(CHDbContext dbContext) } - public async Task CreateEnergyRateAsync(CreateEnergyRateCommandOptions options, CancellationToken cancellationToken) + public async Task CreateEnergyRateAsync(AddEnergyRateCommandOptions options, CancellationToken cancellationToken) { var provider = await dbContext.EnergyProviders.FirstOrDefaultAsync(provider => provider.Id == options.ProviderId, cancellationToken); var energyRate = new EnergyRate @@ -39,7 +39,7 @@ public class EnergyService(CHDbContext dbContext) } - public async Task CreateEnergyRateExceptionAsync(CreateEnergyRateExceptionCommandOptions options, + public async Task AddEnergyRateExceptionAsync(AddEnergyRateExceptionCommandOptions options, CancellationToken cancellationToken) { var energyRate = await dbContext.EnergyRates.FirstOrDefaultAsync(energyRate => energyRate.Id == options.RateId,cancellationToken); diff --git a/CH.CQRS/Service/Energy/Options/CreateEnergyProviderCommandOptions.cs b/CH.CQRS/Service/Energy/Options/AddEnergyProviderCommandOptions.cs similarity index 72% rename from CH.CQRS/Service/Energy/Options/CreateEnergyProviderCommandOptions.cs rename to CH.CQRS/Service/Energy/Options/AddEnergyProviderCommandOptions.cs index 52778da..f288428 100644 --- a/CH.CQRS/Service/Energy/Options/CreateEnergyProviderCommandOptions.cs +++ b/CH.CQRS/Service/Energy/Options/AddEnergyProviderCommandOptions.cs @@ -1,6 +1,6 @@ namespace CH.CQRS.Service.Energy.Options; -public class CreateEnergyProviderCommandOptions +public class AddEnergyProviderCommandOptions { public required string Name { get; set; } public bool Active { get; set; } diff --git a/CH.CQRS/Service/Energy/Options/CreateEnergyRateCommandOptions.cs b/CH.CQRS/Service/Energy/Options/AddEnergyRateCommandOptions.cs similarity index 87% rename from CH.CQRS/Service/Energy/Options/CreateEnergyRateCommandOptions.cs rename to CH.CQRS/Service/Energy/Options/AddEnergyRateCommandOptions.cs index 2298aeb..b321fd5 100644 --- a/CH.CQRS/Service/Energy/Options/CreateEnergyRateCommandOptions.cs +++ b/CH.CQRS/Service/Energy/Options/AddEnergyRateCommandOptions.cs @@ -3,7 +3,7 @@ using CH.Enum; namespace CH.CQRS.Service.Energy.Options; -public class CreateEnergyRateCommandOptions +public class AddEnergyRateCommandOptions { public long ProviderId { get; set; } public required string Name { get; set; } diff --git a/CH.CQRS/Service/Energy/Options/CreateEnergyRateExceptionCommandOptions.cs b/CH.CQRS/Service/Energy/Options/AddEnergyRateExceptionCommandOptions.cs similarity index 86% rename from CH.CQRS/Service/Energy/Options/CreateEnergyRateExceptionCommandOptions.cs rename to CH.CQRS/Service/Energy/Options/AddEnergyRateExceptionCommandOptions.cs index 4f034ca..0c371f8 100644 --- a/CH.CQRS/Service/Energy/Options/CreateEnergyRateExceptionCommandOptions.cs +++ b/CH.CQRS/Service/Energy/Options/AddEnergyRateExceptionCommandOptions.cs @@ -2,7 +2,7 @@ using CH.Enum; namespace CH.CQRS.Service.Energy.Options; -public class CreateEnergyRateExceptionCommandOptions +public class AddEnergyRateExceptionCommandOptions { public long RateId { get; set; } public required string Name { get; set; }