using AsbCloudApp.Data; using AsbCloudApp.Data.WITS; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { internal class FactualTrajectoryRepository : IFactualTrajectoryRepository { private readonly IAsbCloudDbContext db; private readonly IWellService wellService; public FactualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) { this.db = db; this.wellService = wellService; } public async Task> GetAsync(int idWell, CancellationToken token) { var well = wellService.GetOrDefault(idWell); if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); var query = db.Record7 .AsNoTracking() .Where(x => x.IdTelemetry == well.IdTelemetry); var entities = await query .OrderBy(e => e.Deptsvym) .ToListAsync(token); var result = entities .Select(r => r.Adapt()); return result; } public async Task GetTrajectoryAsync(int idWell, CancellationToken token) { return (await GetAsync(idWell, token)) .Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null) .Select(coord => new TrajectoryDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value)) .ToArray(); } } }