DepositRepository.GetAsync(..) полная материализация ответа, чтобы понять где именно возникает ошибка на проде.

This commit is contained in:
ngfrolov 2024-05-20 09:20:48 +05:00
parent 43b89b8db8
commit 478297a871
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
4 changed files with 94 additions and 142 deletions

View File

@ -19,15 +19,6 @@ namespace AsbCloudApp.Repositories
Task<IEnumerable<DepositDto>> GetAsync(int idCompany, Task<IEnumerable<DepositDto>> GetAsync(int idCompany,
CancellationToken token); CancellationToken token);
/// <summary>
/// Список месторождений/кустов/скважин у которых заполненны параметры бурения
/// </summary>
/// <param name="idCompany"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<DepositDto>> GetAllWithDrillParamsAsync(int idCompany,
CancellationToken token = default);
/// <summary> /// <summary>
/// Список кустов месторождения доступных компании /// Список кустов месторождения доступных компании
/// </summary> /// </summary>

View File

@ -10,11 +10,10 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository namespace AsbCloudInfrastructure.Repository;
{
public class DepositRepository : IDepositRepository public class DepositRepository : IDepositRepository
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
@ -28,38 +27,19 @@ namespace AsbCloudInfrastructure.Repository
public async Task<IEnumerable<DepositDto>> GetAsync(int idCompany, public async Task<IEnumerable<DepositDto>> GetAsync(int idCompany,
CancellationToken token = default) CancellationToken token = default)
{ {
var wellEntities = await (from well in db.Wells var wellsQuery = db.Set<Well>()
.Include(w => w.RelationCompaniesWells) .Include(w => w.RelationCompaniesWells)
.Include(w => w.WellType) .Include(w => w.WellType)
.Include(w => w.Cluster) .Include(w => w.Cluster)
.ThenInclude(c => c.Deposit) .ThenInclude(c => c.Deposit)
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany) .Where(well => well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany));
select well).ToListAsync(token)
.ConfigureAwait(false); var wellEntities = await wellsQuery.ToArrayAsync(token);
var gDepositEntities = GroupWells(wellEntities); var gDepositEntities = GroupWells(wellEntities);
var dtos = CreateDepositDto(gDepositEntities); var dtos = CreateDepositDto(gDepositEntities)
.ToArray();
return dtos;
}
/// <inheritdoc/>
public async Task<IEnumerable<DepositDto>> GetAllWithDrillParamsAsync(int idCompany,
CancellationToken token = default)
{
var wellEntities = await (from well in db.Wells
.Include(w => w.RelationCompaniesWells)
.Include(w => w.WellType)
.Include(w => w.Cluster)
.ThenInclude(c => c.Deposit)
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
select well).ToListAsync(token)
.ConfigureAwait(false);
var gDepositEntities = GroupWells(wellEntities);
var dtos = CreateDepositDto(gDepositEntities);
return dtos; return dtos;
} }
@ -87,7 +67,7 @@ namespace AsbCloudInfrastructure.Repository
.GroupBy(c => c.Key.Deposit); .GroupBy(c => c.Key.Deposit);
private IQueryable<Well> GetWellsForCompany(int idCompany) private IQueryable<Well> GetWellsForCompany(int idCompany)
=> db.Wells => db.Set<Well>()
.Include(w => w.RelationCompaniesWells) .Include(w => w.RelationCompaniesWells)
.ThenInclude(r => r.Company) .ThenInclude(r => r.Company)
.Include(w => w.Cluster) .Include(w => w.Cluster)
@ -126,6 +106,4 @@ namespace AsbCloudInfrastructure.Repository
}); });
return dtos; return dtos;
} }
}
} }

View File

@ -43,26 +43,6 @@ namespace AsbCloudWebApi.Controllers
return Ok(result); return Ok(result);
} }
/// <summary>
/// Получает список доступных пользователю месторождений (только скважины с параметрами бурения)
/// </summary>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpGet("drillParamsWells")]
[Permission]
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetDepositsDrillParamsAsync(CancellationToken token)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var result = await depositService.GetAllWithDrillParamsAsync((int)idCompany,
token).ConfigureAwait(false);
return Ok(result);
}
/// <summary> /// <summary>
/// Получает список доступных пользователю кустов месторождения /// Получает список доступных пользователю кустов месторождения
/// </summary> /// </summary>

View File

@ -44,6 +44,9 @@ namespace AsbCloudWebApi.Middlewares
} }
catch (Exception ex) // TODO: find explicit exception. Use Trace. Add body size to message. catch (Exception ex) // TODO: find explicit exception. Use Trace. Add body size to message.
{ {
if (context.Response.HasStarted)
throw;
context.Response.Clear(); context.Response.Clear();
context.Response.StatusCode = 500; context.Response.StatusCode = 500;