2024-11-14 15:17:43 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Persistence.Models;
|
|
|
|
|
using Persistence.Repositories;
|
|
|
|
|
using Persistence.Database.Model;
|
|
|
|
|
using Persistence.Repository.Data;
|
2024-11-15 16:29:15 +05:00
|
|
|
|
using Persistence.Database;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
|
|
namespace Persistence.Repository.Repositories;
|
2024-11-15 16:29:15 +05:00
|
|
|
|
public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository<TDto>
|
2024-11-14 15:17:43 +05:00
|
|
|
|
where TEntity : class
|
|
|
|
|
where TDto : class, ITimeSeriesAbstractDto, new()
|
|
|
|
|
{
|
|
|
|
|
private DbContext db;
|
|
|
|
|
|
|
|
|
|
public TimeSeriesDataRepository(DbContext db)
|
|
|
|
|
{
|
|
|
|
|
this.db = db;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-15 16:29:15 +05:00
|
|
|
|
protected virtual IQueryable<TEntity> GetQueryReadOnly() => this.db.Set<TEntity>();
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TDto>> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var query = GetQueryReadOnly();
|
|
|
|
|
var entities = await query.ToArrayAsync(token);
|
|
|
|
|
var dtos = entities.Select(e => e.Adapt<TDto>());
|
|
|
|
|
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> InsertRange(IEnumerable<TDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var entities = dtos.Select(d => d.Adapt<TEntity>());
|
|
|
|
|
|
|
|
|
|
await db.Set<TEntity>().AddRangeAsync(entities, token);
|
|
|
|
|
var result = await db.SaveChangesAsync(token);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|