change command name from create to add
This commit is contained in:
parent
561d10fceb
commit
ef674cefea
@ -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<CreateEnergyProviderCommand>
|
||||
public class AddEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler<AddEnergyProviderCommand>
|
||||
{
|
||||
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<CreateEnergyProviderCommand>
|
||||
public class AddEnergyProviderCommandValidator : AbstractValidator<AddEnergyProviderCommand>
|
||||
{
|
||||
public CreateEnergyProviderCommandValidator(CHDbContext dbContext)
|
||||
public AddEnergyProviderCommandValidator(CHDbContext dbContext)
|
||||
{
|
||||
RuleFor(command => command.Name)
|
||||
.NotEmpty()
|
@ -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<CreateEnergyRateCommand>
|
||||
public class AddEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler<AddEnergyRateCommand>
|
||||
{
|
||||
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<CreateEnergyRateCommand>
|
||||
public class AddEnergyRateCommandValidator : AbstractValidator<AddEnergyRateCommand>
|
||||
{
|
||||
public CreateEnergyRateCommandValidator(CHDbContext dbContext)
|
||||
public AddEnergyRateCommandValidator(CHDbContext dbContext)
|
||||
{
|
||||
RuleFor(command => command.Name)
|
||||
.NotEmpty()
|
@ -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<CreateEnergyRateExceptionCommand>
|
||||
public class AddEnergyRateExceptionCommandHandler(EnergyService energyService) : ICommandHandler<AddEnergyRateExceptionCommand>
|
||||
{
|
||||
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<CreateEnergyRateExceptionCommand>
|
||||
public class AddEnergyRateExceptionCommandValidator : AbstractValidator<AddEnergyRateExceptionCommand>
|
||||
{
|
||||
public CreateEnergyRateExceptionCommandValidator(CHDbContext dbContext)
|
||||
public AddEnergyRateExceptionCommandValidator(CHDbContext dbContext)
|
||||
{
|
||||
RuleFor(command => command.Name)
|
||||
.NotEmpty()
|
@ -8,14 +8,14 @@ public static class ServiceCollectionExtension
|
||||
public static IServiceCollection AddEnergyCommand(this IServiceCollection services)
|
||||
{
|
||||
services
|
||||
.AddCommand<CreateEnergyProviderCommand, CreateEnergyProviderCommandHandler,
|
||||
CreateEnergyProviderCommandValidator>();
|
||||
.AddCommand<AddEnergyProviderCommand, AddEnergyProviderCommandHandler,
|
||||
AddEnergyProviderCommandValidator>();
|
||||
services
|
||||
.AddCommand<CreateEnergyRateCommand, CreateEnergyRateCommandHandler,
|
||||
CreateEnergyRateCommandValidator>();
|
||||
.AddCommand<AddEnergyRateCommand, AddEnergyRateCommandHandler,
|
||||
AddEnergyRateCommandValidator>();
|
||||
services
|
||||
.AddCommand<CreateEnergyRateExceptionCommand, CreateEnergyRateExceptionCommandHandler,
|
||||
CreateEnergyRateExceptionCommandValidator>();
|
||||
.AddCommand<AddEnergyRateExceptionCommand, AddEnergyRateExceptionCommandHandler,
|
||||
AddEnergyRateExceptionCommandValidator>();
|
||||
services
|
||||
.AddCommand<DisableEnergyProviderCommand, DisableEnergyProviderCommandHandler,
|
||||
DisableEnergyProviderCommandValidator>();
|
||||
|
@ -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<CryptoStatQuery, CH.CryptoStats.Abstractions.CryptoStats>
|
||||
public class CryptoStatQueryHandler(CoinMarketCapService coinMarketCapService) : IQueryHandler<CryptoStatQuery, CryptoStatQueryResult>
|
||||
{
|
||||
public Task<CH.CryptoStats.Abstractions.CryptoStats> HandleAsync(CryptoStatQuery query, CancellationToken cancellationToken = new CancellationToken())
|
||||
public async Task<CryptoStatQueryResult> HandleAsync(CryptoStatQuery query, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return coinMarketCapService.GetCryptoStatsAsync(query.CoinName, query.Currency, cancellationToken);
|
||||
var listCrypto = new List<CH.CryptoStats.Abstractions.CryptoStats>();
|
||||
var cryptoStats = await coinMarketCapService.GetCryptoStatsAsync("bitcoin", "cad", cancellationToken);
|
||||
listCrypto.Add(cryptoStats);
|
||||
var listStat = new CryptoStatQueryResult
|
||||
{
|
||||
Data = listCrypto
|
||||
};
|
||||
return listStat;
|
||||
}
|
||||
}
|
8
CH.CQRS/Query/CryptoStat/CryptoStatQueryResult.cs
Normal file
8
CH.CQRS/Query/CryptoStat/CryptoStatQueryResult.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
|
||||
namespace CH.CQRS.Query.CryptoStat;
|
||||
|
||||
public class CryptoStatQueryResult
|
||||
{
|
||||
public required List<CH.CryptoStats.Abstractions.CryptoStats> Data { get; set; }
|
||||
}
|
@ -21,7 +21,7 @@ public class QueryModule : IModule
|
||||
services.AddQuery<EnergyProviderQuery, EnergyProviderQueryResult, EnergyProviderQueryHandler>();
|
||||
services.AddQuery<EnergyRateQuery, EnergyRateQueryResult, EnergyRateQueryHandler>();
|
||||
services.AddQuery<EnergyRateExceptionQuery, EnergyRateExceptionQueryResult, EnergyRateExceptionQueryHandler>();
|
||||
services.AddQuery<CryptoStatQuery, CH.CryptoStats.Abstractions.CryptoStats, CryptoStatQueryHandler>();
|
||||
services.AddQuery<CryptoStatQuery, CryptoStatQueryResult, CryptoStatQueryHandler>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
@ -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; }
|
@ -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; }
|
Loading…
Reference in New Issue
Block a user