constellation-api/CH.CQRS/Query/EnergyProvider/EnergyProviderQuery.cs

54 lines
1.2 KiB
C#
Raw Normal View History

using CH.Dal;
using Microsoft.EntityFrameworkCore;
using OpenHarbor.CQRS.Abstractions;
using PoweredSoft.DynamicLinq;
namespace CH.CQRS.Query.EnergyProvider;
public class EnergyProviderQuery
{
}
public class EnergyProviderQueryItem
{
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<EnergyProviderQueryItem>
{
public async Task<IQueryable<EnergyProviderQueryItem>> 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;
}
}