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,
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>

View File

@ -10,8 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
namespace AsbCloudInfrastructure.Repository;
public class DepositRepository : IDepositRepository
{
@ -28,38 +27,19 @@ namespace AsbCloudInfrastructure.Repository
public async Task<IEnumerable<DepositDto>> GetAsync(int idCompany,
CancellationToken token = default)
{
var wellEntities = await (from well in db.Wells
var wellsQuery = db.Set<Well>()
.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);
.Where(well => well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany));
var wellEntities = await wellsQuery.ToArrayAsync(token);
var gDepositEntities = GroupWells(wellEntities);
var dtos = CreateDepositDto(gDepositEntities);
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);
var dtos = CreateDepositDto(gDepositEntities)
.ToArray();
return dtos;
}
@ -87,7 +67,7 @@ namespace AsbCloudInfrastructure.Repository
.GroupBy(c => c.Key.Deposit);
private IQueryable<Well> GetWellsForCompany(int idCompany)
=> db.Wells
=> db.Set<Well>()
.Include(w => w.RelationCompaniesWells)
.ThenInclude(r => r.Company)
.Include(w => w.Cluster)
@ -127,5 +107,3 @@ namespace AsbCloudInfrastructure.Repository
return dtos;
}
}
}

View File

@ -43,26 +43,6 @@ namespace AsbCloudWebApi.Controllers
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>

View File

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