Add NotFoundException handling to ReadOutResHandler

Updated `using` directives to include `DigitalData.Core.Exceptions` for custom exception handling. Renamed `dtos` to `resList` for clarity. Added a check to throw `NotFoundException` when no results are found in the query. Updated the return logic to ensure mapping occurs only when results exist. These changes enhance error handling and improve code robustness.
This commit is contained in:
tekh 2025-12-04 10:13:46 +01:00
parent 2cd7c035eb
commit 534b254d0a

View File

@ -1,5 +1,6 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Application.Common.Dto;
@ -26,8 +27,11 @@ public class ReadOutResHandler(IRepository<OutRes> repo, IMapper mapper) : IRequ
if(request.ProfileId is long profileId)
q = q.Where(res => res.Action!.ProfileId == profileId);
var dtos = await q.ToListAsync(cancel);
var resList = await q.ToListAsync(cancel);
return mapper.Map<OutResDto>(dtos);
if (resList.Count == 0)
throw new NotFoundException();
return mapper.Map<OutResDto>(resList);
}
}