refactor(unitFilterService): логика фильтрации связанных ЭК перенесена в класс, который за это отвечает.

This commit is contained in:
Mikhail Kuznetsov
2026-07-31 10:46:48 +10:00
parent 94bea5c46d
commit fb20395e53
4 changed files with 98 additions and 432 deletions

View File

@@ -27,38 +27,14 @@ namespace PARR.DAL.Repositories.Unit
}
public Task<List<UnitInUnit>> GetByParentIdAsync(Guid parentId)
public async Task<List<Guid>> GetRelatedUnitIdsAsync(Guid unitId, CancellationToken ct = default)
{
return dataContext.UnitInUnits
.Where(u => u.ParentUnitId == parentId)
.ToListAsync();
}
public Task<List<UnitInUnit>> GetByChildIdAsync(Guid childId)
{
return dataContext.UnitInUnits
.Where(u => u.ChildUnitId == childId)
.ToListAsync();
}
public async Task<List<UnitInUnit>> GetParentLinksByChildIdsAsync(IEnumerable<Guid> childUnitIds)
{
var set = childUnitIds.ToHashSet();
return await dataContext.UnitInUnits
return await Get()
.AsNoTracking()
.Where(uinu => set.Contains(uinu.ChildUnitId))
.ToListAsync();
}
public async Task<List<UnitInUnit>> GetChildLinksByParentIdsAsync(IEnumerable<Guid> parentUnitIds)
{
var set = parentUnitIds.ToHashSet();
return await dataContext.UnitInUnits
.AsNoTracking()
.Where(uinu => set.Contains(uinu.ParentUnitId))
.ToListAsync();
.Where(link => link.ChildUnitId == unitId || link.ParentUnitId == unitId)
.Select(link => link.ChildUnitId == unitId ? link.ParentUnitId : link.ChildUnitId)
.Distinct()
.ToListAsync(ct);
}
}
}