Api/Netina.Repository/Handlers/Reviews/GetReviewQueryHandler.cs

19 lines
722 B
C#

using Review = Netina.Domain.Entities.Reviews.Review;
namespace Netina.Repository.Handlers.Reviews;
public class GetReviewQueryHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<GetReviewQuery, ReviewLDto>
{
public async Task<ReviewLDto> Handle(GetReviewQuery request, CancellationToken cancellationToken)
{
var review = await repositoryWrapper.SetRepository<Review>()
.TableNoTracking
.Where(r => r.Id == request.Id)
.Select(ReviewMapper.ProjectToLDto)
.FirstOrDefaultAsync(cancellationToken);
if (review == null)
throw new AppException("Review not found", ApiResultStatusCode.NotFound);
return review;
}
}