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