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> /// </summary>
/// <returns></returns> /// <returns></returns>
IEnumerable<WellOperationCategoryDto> GetCategories(); IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents);
/// <summary> /// <summary>
/// Список секций /// Список секций

View File

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

View File

@ -138,7 +138,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
IEnumerable<int> idsWells; IEnumerable<int> idsWells;
if (idCluster is not null) 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) idsWells = companyWells.Where(w => w.IdCluster == idCluster)
.Select(w=>w.Id); .Select(w=>w.Id);
} }

View File

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