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:
parent
2cd7c035eb
commit
534b254d0a
@ -1,5 +1,6 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using DigitalData.Core.Exceptions;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using ReC.Application.Common.Dto;
|
using ReC.Application.Common.Dto;
|
||||||
@ -26,8 +27,11 @@ public class ReadOutResHandler(IRepository<OutRes> repo, IMapper mapper) : IRequ
|
|||||||
if(request.ProfileId is long profileId)
|
if(request.ProfileId is long profileId)
|
||||||
q = q.Where(res => res.Action!.ProfileId == 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user