feat(application): RubroTreeBuilder + GetRubroTree con tieneAvisos (CAT-002)

This commit is contained in:
2026-04-19 08:25:13 -03:00
parent c03aad8c5a
commit f861dfa826
2 changed files with 80 additions and 6 deletions

View File

@@ -8,16 +8,20 @@ namespace SIGCM2.Application.Rubros.GetTree;
public sealed class GetRubroTreeQueryHandler : ICommandHandler<GetRubroTreeQuery, IReadOnlyList<RubroTreeNodeDto>>
{
private readonly IRubroRepository _repo;
private readonly IAvisoQueryRepository _avisoQuery;
public GetRubroTreeQueryHandler(IRubroRepository repo)
public GetRubroTreeQueryHandler(IRubroRepository repo, IAvisoQueryRepository avisoQuery)
{
_repo = repo;
_avisoQuery = avisoQuery;
}
public async Task<IReadOnlyList<RubroTreeNodeDto>> Handle(GetRubroTreeQuery query)
{
var all = await _repo.GetAllAsync(query.IncluirInactivos);
// CAT-002: avisoCounts injected via IAvisoQueryRepository (wired in Batch 6)
return RubroTreeBuilder.Build(all, query.IncluirInactivos, new Dictionary<int, int>());
var ids = all.Select(r => r.Id).ToList();
// CAT-002: single batch call — avoids N+1 when PRD-002 activates the real implementation
var avisoCounts = await _avisoQuery.CountAvisosBatchAsync(ids);
return RubroTreeBuilder.Build(all, query.IncluirInactivos, avisoCounts);
}
}