diff --git a/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs b/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs index 05924d8..35eb954 100644 --- a/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs +++ b/CH.CQRS/Query/CryptoStat/CryptoStatQuery.cs @@ -6,8 +6,7 @@ namespace CH.CQRS.Query.CryptoStat; public class CryptoStatQuery { - // public required string CoinName { get; set; } - // public required string Currency { get; set; } + } public class CryptoStatQueryHandler(CoinMarketCapService coinMarketCapService) : IQueryHandler { diff --git a/CH.CQRS/Query/EnergyProvider/EnergyProviderQueriesModule.cs b/CH.CQRS/Query/EnergyProvider/EnergyProviderQueriesModule.cs new file mode 100644 index 0000000..147064d --- /dev/null +++ b/CH.CQRS/Query/EnergyProvider/EnergyProviderQueriesModule.cs @@ -0,0 +1,16 @@ +using CH.Dal; +using Microsoft.Extensions.DependencyInjection; +using OpenHarbor.CQRS.DynamicQuery; +using PoweredSoft.Module.Abstractions; + +namespace CH.CQRS.Query.EnergyProvider; + +public class EnergyProviderQueriesModule : IModule +{ + public IServiceCollection ConfigureServices(IServiceCollection services) + { + services.AddDynamicQuery() + .AddQueryableProviderOverride(); + return services; + } +} \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyProvider/EnergyProviderQuery.cs b/CH.CQRS/Query/EnergyProvider/EnergyProviderQuery.cs index 2cb66bf..e7eb263 100644 --- a/CH.CQRS/Query/EnergyProvider/EnergyProviderQuery.cs +++ b/CH.CQRS/Query/EnergyProvider/EnergyProviderQuery.cs @@ -1,6 +1,7 @@ using CH.Dal; using Microsoft.EntityFrameworkCore; using OpenHarbor.CQRS.Abstractions; +using PoweredSoft.DynamicLinq; namespace CH.CQRS.Query.EnergyProvider; @@ -8,15 +9,46 @@ public class EnergyProviderQuery { } -public class EnergyProviderQueryHandler(CHDbContext dbContext) : IQueryHandler + +public class EnergyProviderQueryItem { - public async Task HandleAsync(EnergyProviderQuery query, CancellationToken cancellationToken = new CancellationToken()) - { - var energyProviders = await dbContext.EnergyProviders.ToListAsync(cancellationToken); - var energyProviderQueryResult = new EnergyProviderQueryResult - { - Data = energyProviders - }; - return energyProviderQueryResult; + public long Id { get; set; } + + public string Name { get; set; } = null!; + + public bool Active { get; set; } + + public DateTime? DisabledAt { get; set; } + + public DateTime CreatedAt { get; set; } + + public DateTime? UpdatedAt { get; set; } +} + +public class EnergyRateQueryParams +{ + +} +public class EnergyProviderQueryableProvider(CHDbContext dbContext) : IQueryableProviderOverride +{ + public async Task> GetQueryableAsync(object query, CancellationToken cancellationToken = default) + { + var queryable = dbContext.EnergyProviders + .AsNoTracking() + .AsQueryable(); + + var result = queryable + .Select(energyProvider => new EnergyProviderQueryItem + { + Id = energyProvider.Id, + Name = energyProvider.Name, + Active = energyProvider.Active, + DisabledAt = energyProvider.DisabledAt, + CreatedAt = energyProvider.CreatedAt, + UpdatedAt = energyProvider.UpdatedAt + + }); + + return result; } } \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyProvider/EnergyProviderQueryResult.cs b/CH.CQRS/Query/EnergyProvider/EnergyProviderQueryResult.cs deleted file mode 100644 index 557041a..0000000 --- a/CH.CQRS/Query/EnergyProvider/EnergyProviderQueryResult.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CH.CQRS.Query.EnergyProvider; - -public class EnergyProviderQueryResult -{ - public required List Data { get; set; } -} \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyRate/EnergyRateQueriesModule.cs b/CH.CQRS/Query/EnergyRate/EnergyRateQueriesModule.cs new file mode 100644 index 0000000..bb61dec --- /dev/null +++ b/CH.CQRS/Query/EnergyRate/EnergyRateQueriesModule.cs @@ -0,0 +1,17 @@ +using CH.Dal; +using Microsoft.Extensions.DependencyInjection; +using OpenHarbor.CQRS.DynamicQuery; +using PoweredSoft.Module.Abstractions; + +namespace CH.CQRS.Query.EnergyRate; + +public class EnergyRateQueriesModule : IModule +{ + public IServiceCollection ConfigureServices(IServiceCollection services) + { + services.AddDynamicQueryWithParams() + .AddQueryableProviderOverride(); + + return services; + } +} \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyRate/EnergyRateQuery.cs b/CH.CQRS/Query/EnergyRate/EnergyRateQuery.cs index 0df763a..ff8c5fe 100644 --- a/CH.CQRS/Query/EnergyRate/EnergyRateQuery.cs +++ b/CH.CQRS/Query/EnergyRate/EnergyRateQuery.cs @@ -2,22 +2,63 @@ using CH.CQRS.Query.EnergyProvider; using CH.Dal; using Microsoft.EntityFrameworkCore; using OpenHarbor.CQRS.Abstractions; +using OpenHarbor.CQRS.DynamicQuery.Abstractions; namespace CH.CQRS.Query.EnergyRate; public class EnergyRateQuery { - } -public class EnergyRateQueryHandler(CHDbContext dbContext) : IQueryHandler + +public class EnergyRateQueryItem { - public async Task HandleAsync(EnergyRateQuery query, CancellationToken cancellationToken = new CancellationToken()) + public long Id { get; set; } + public long? ProviderId { get; set; } + public required string Name { get; set; } + public decimal? Rate { get; set; } + public bool Active { get; set; } + public DateTime? DiabledAt { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } +} + +public class EnergyRateQueryParams +{ + public long EnergyProviderId { get; set; } +} + +public class EnergyRateQueryableProvider(CHDbContext dbContext) : IQueryableProviderOverride +{ + public async Task> GetQueryableAsync(object query, CancellationToken cancellationToken = default) { - var energyRates = await dbContext.EnergyRates.ToListAsync(cancellationToken); - var energyRateQueryResult = new EnergyRateQueryResult + long? energyProviderId = null; + if (query is IDynamicQueryParams queryParams) { - Data = energyRates - }; - return energyRateQueryResult; + var parameters = queryParams.GetParams(); + energyProviderId = parameters.EnergyProviderId; + } + + if (false == energyProviderId.HasValue) + return Enumerable.Empty().AsQueryable(); + + var queryable = dbContext.EnergyRates + .AsNoTracking() + .AsQueryable(); + + var result = queryable + .Where(energyRate => energyRate.ProviderId == energyProviderId) + .Select(energyRate => new EnergyRateQueryItem + { + Id = energyRate.Id, + ProviderId = energyRate.ProviderId, + Name = energyRate.Name, + Rate = energyRate.Rate, + Active = energyRate.Active, + DiabledAt = energyRate.DisabledAt, + CreatedAt = energyRate.CreatedAt, + UpdatedAt = energyRate.UpdatedAt + }); + + return result; } } \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyRate/EnergyRateQueryResult.cs b/CH.CQRS/Query/EnergyRate/EnergyRateQueryResult.cs deleted file mode 100644 index 6bc92b4..0000000 --- a/CH.CQRS/Query/EnergyRate/EnergyRateQueryResult.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CH.CQRS.Query.EnergyRate; - -public class EnergyRateQueryResult -{ - public required List Data { get; set; } -} \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQueriesModule.cs b/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQueriesModule.cs new file mode 100644 index 0000000..32c615f --- /dev/null +++ b/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQueriesModule.cs @@ -0,0 +1,16 @@ +using CH.Dal; +using Microsoft.Extensions.DependencyInjection; +using OpenHarbor.CQRS.DynamicQuery; +using PoweredSoft.Module.Abstractions; + +namespace CH.CQRS.Query.EnergyRateException; + +public class EnergyRateExceptionQueriesModule : IModule +{ + public IServiceCollection ConfigureServices(IServiceCollection services) + { + services.AddDynamicQueryWithParams() + .AddQueryableProviderOverride(); + return services; + } +} \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQuery.cs b/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQuery.cs index 0385dcf..258c5ad 100644 --- a/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQuery.cs +++ b/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQuery.cs @@ -1,22 +1,72 @@ +using CH.CQRS.Query.EnergyProvider; using CH.Dal; +using CH.Enum; using Microsoft.EntityFrameworkCore; using OpenHarbor.CQRS.Abstractions; +using OpenHarbor.CQRS.DynamicQuery.Abstractions; namespace CH.CQRS.Query.EnergyRateException; public class EnergyRateExceptionQuery { - } -public class EnergyRateExceptionQueryHandler(CHDbContext dbContext) : IQueryHandler + +public class EnergyRateExceptionQueryItem { - public async Task HandleAsync(EnergyRateExceptionQuery query, CancellationToken cancellationToken = new CancellationToken()) + public long Id { get; set; } + + public long? RateId { get; set; } + + public string? Name { get; set; } + + public decimal? EnergyThreshold { get; set; } + + public EnergyRateExceptionThresholdResetType ResetType { get; set; } + + public DateTime? StartedAt { get; set; } + + public DateTime? EndedAt { get; set; } + + public DateTime CreatedAt { get; set; } + + public DateTime? UpdatedAt { get; set; } +} + +public class EnergyRateExceptionQueryParams +{ + public long EnergyRateId { get; set; } +} +public class EnergyRateExceptionQueryableProvider(CHDbContext dbContext) : IQueryableProviderOverride +{ + public async Task> GetQueryableAsync(object query, CancellationToken cancellationToken = default) { - var energyRateExceptions = await dbContext.EnergyRateExceptions.ToListAsync(cancellationToken); - var energyRateExceptionsQueryResult = new EnergyRateExceptionQueryResult + long? energyRateId = null; + if (query is IDynamicQueryParams queryParams) { - Data = energyRateExceptions, - }; - return energyRateExceptionsQueryResult; + var parameters = queryParams.GetParams(); + energyRateId = parameters.EnergyRateId; + } + + if(false == energyRateId.HasValue) + return Enumerable.Empty().AsQueryable(); + + var queryable = dbContext.EnergyRateExceptions + .AsNoTracking() + .AsQueryable(); + + var result = queryable + .Where(energyRateException => energyRateException.RateId == energyRateId) + .Select(energyRateException => new EnergyRateExceptionQueryItem + { + Id = energyRateException.Id, + Name = energyRateException.Name, + EnergyThreshold = energyRateException.EnergyThreshold, + ResetType = energyRateException.ResetType, + StartedAt = energyRateException.StartedAt, + EndedAt = energyRateException.EndedAt, + CreatedAt = energyRateException.CreatedAt, + UpdatedAt = energyRateException.UpdatedAt, + }); + return result; } } \ No newline at end of file diff --git a/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQueryResult.cs b/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQueryResult.cs deleted file mode 100644 index a54a8f3..0000000 --- a/CH.CQRS/Query/EnergyRateException/EnergyRateExceptionQueryResult.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CH.CQRS.Query.EnergyRateException; - -public class EnergyRateExceptionQueryResult -{ - 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 ba2e8ea..11e832e 100644 --- a/CH.CQRS/QueryModule.cs +++ b/CH.CQRS/QueryModule.cs @@ -18,10 +18,11 @@ public class QueryModule : IModule public IServiceCollection ConfigureServices(IServiceCollection services) { services.AddQuery(); - services.AddQuery(); - services.AddQuery(); - services.AddQuery(); services.AddQuery(); + services.AddModule(); + services.AddModule(); + services.AddModule(); + return services; } }