add query energy provider, rate, rate exception

This commit is contained in:
DavidGudEnough 2025-01-17 17:43:26 -05:00
parent 1451314d56
commit 04ded7c21b
Signed by: david.nguyen
GPG Key ID: 0B95DC36355BEB37
7 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,22 @@
using CH.Dal;
using Microsoft.EntityFrameworkCore;
using OpenHarbor.CQRS.Abstractions;
namespace CH.CQRS.Query.EnergyProvider;
public class EnergyProviderQuery
{
}
public class EnergyProviderQueryHandler(CHDbContext dbContext) : IQueryHandler<EnergyProviderQuery, EnergyProviderQueryResult>
{
public async Task<EnergyProviderQueryResult> HandleAsync(EnergyProviderQuery query, CancellationToken cancellationToken = new CancellationToken())
{
var energyProviders = await dbContext.EnergyProviders.ToListAsync(cancellationToken);
var energyProviderQueryResult = new EnergyProviderQueryResult
{
Data = energyProviders
};
return energyProviderQueryResult;
}
}

View File

@ -0,0 +1,6 @@
namespace CH.CQRS.Query.EnergyProvider;
public class EnergyProviderQueryResult
{
public required List<Dal.DbEntity.EnergyProvider> Data { get; set; }
}

View File

@ -0,0 +1,23 @@
using CH.CQRS.Query.EnergyProvider;
using CH.Dal;
using Microsoft.EntityFrameworkCore;
using OpenHarbor.CQRS.Abstractions;
namespace CH.CQRS.Query.EnergyRate;
public class EnergyRateQuery
{
}
public class EnergyRateQueryHandler(CHDbContext dbContext) : IQueryHandler<EnergyRateQuery, EnergyRateQueryResult>
{
public async Task<EnergyRateQueryResult> HandleAsync(EnergyRateQuery query, CancellationToken cancellationToken = new CancellationToken())
{
var energyRates = await dbContext.EnergyRates.ToListAsync(cancellationToken);
var energyRateQueryResult = new EnergyRateQueryResult
{
Data = energyRates
};
return energyRateQueryResult;
}
}

View File

@ -0,0 +1,6 @@
namespace CH.CQRS.Query.EnergyRate;
public class EnergyRateQueryResult
{
public required List<Dal.DbEntity.EnergyRate> Data { get; set; }
}

View File

@ -0,0 +1,22 @@
using CH.Dal;
using Microsoft.EntityFrameworkCore;
using OpenHarbor.CQRS.Abstractions;
namespace CH.CQRS.Query.EnergyRateException;
public class EnergyRateExceptionQuery
{
}
public class EnergyRateExceptionQueryHandler(CHDbContext dbContext) : IQueryHandler<EnergyRateExceptionQuery, EnergyRateExceptionQueryResult>
{
public async Task<EnergyRateExceptionQueryResult> HandleAsync(EnergyRateExceptionQuery query, CancellationToken cancellationToken = new CancellationToken())
{
var energyRateExceptions = await dbContext.EnergyRateExceptions.ToListAsync(cancellationToken);
var energyRateExceptionsQueryResult = new EnergyRateExceptionQueryResult
{
Data = energyRateExceptions,
};
return energyRateExceptionsQueryResult;
}
}

View File

@ -0,0 +1,6 @@
namespace CH.CQRS.Query.EnergyRateException;
public class EnergyRateExceptionQueryResult
{
public required List<Dal.DbEntity.EnergyRateException> Data { get; set; }
}

View File

@ -7,6 +7,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CH.CQRS.Query.EnergyProvider;
using CH.CQRS.Query.EnergyRate;
using CH.CQRS.Query.EnergyRateException;
namespace CH.CQRS; namespace CH.CQRS;
public class QueryModule : IModule public class QueryModule : IModule
@ -14,6 +17,9 @@ public class QueryModule : IModule
public IServiceCollection ConfigureServices(IServiceCollection services) public IServiceCollection ConfigureServices(IServiceCollection services)
{ {
services.AddQuery<HealthQuery, HealthQueryResult, HealthQueryHandler>(); services.AddQuery<HealthQuery, HealthQueryResult, HealthQueryHandler>();
services.AddQuery<EnergyProviderQuery, EnergyProviderQueryResult, EnergyProviderQueryHandler>();
services.AddQuery<EnergyRateQuery, EnergyRateQueryResult, EnergyRateQueryHandler>();
services.AddQuery<EnergyRateExceptionQuery, EnergyRateExceptionQueryResult, EnergyRateExceptionQueryHandler>();
return services; return services;
} }
} }