WellOperationRepository.GetCategories(..) add arg, to filter categories/

This commit is contained in:
ngfrolov 2023-02-15 18:02:36 +05:00
parent eb18d73dd0
commit 7779116c8a
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
4 changed files with 18 additions and 13 deletions

View File

@ -17,7 +17,7 @@ namespace AsbCloudApp.Repositories
/// список названий операций
/// </summary>
/// <returns></returns>
IEnumerable<WellOperationCategoryDto> GetCategories();
IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents);
/// <summary>
/// Список секций

View File

@ -34,21 +34,26 @@ namespace AsbCloudInfrastructure.Repository
}
/// <inheritdoc/>
public IEnumerable<WellOperationCategoryDto> GetCategories()
public IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents)
{
var allCategories = memoryCache
var categories = memoryCache
.GetOrCreateBasic<WellOperationCategory>(db);
var parentIds = allCategories
.Select(o => o.IdParent)
.Distinct();
if (!includeParents)
{
var parentIds = categories
.Select(o => o.IdParent)
.Distinct();
var operationCategories = allCategories
.Where(o => !parentIds.Contains(o.Id))
categories = categories
.Where(o => !parentIds.Contains(o.Id));
}
var result = categories
.OrderBy(o => o.IdParent)
.ThenBy(o => o.Name);
.ThenBy(o => o.Name)
.Adapt<IEnumerable<WellOperationCategoryDto>>();
var result = operationCategories.Adapt<IEnumerable<WellOperationCategoryDto>>();
return result;
}
@ -149,7 +154,7 @@ namespace AsbCloudInfrastructure.Repository
DurationDepth = o.DepthEnd - o.DepthStart
})
.ToListAsync(token);
var parentRelationDictionary = GetCategories()
var parentRelationDictionary = GetCategories(true)
.ToDictionary(c => c.Id, c => new
{
c.Name,

View File

@ -138,7 +138,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
IEnumerable<int> idsWells;
if (idCluster is not null)
{
var companyWells = await wellService.GetWellsByCompanyAsync((int)idCompany, token);
var companyWells = await wellService.GetAsync(new() { IdCompany = idCompany }, token);
idsWells = companyWells.Where(w => w.IdCluster == idCluster)
.Select(w=>w.Id);
}

View File

@ -56,7 +56,7 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetCategories()
{
var result = operationRepository.GetCategories();
var result = operationRepository.GetCategories(false);
return Ok(result);
}