feat(application): RubroTreeBuilder + GetRubroTree con tieneAvisos (CAT-002)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user