namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetProductImages;
public class GetProductImagesQueryHandler : IRequestHandler<GetProductImagesQuery, GetProductImagesResponseDto>
{
    private readonly IApplicationDbContext _context;

    public GetProductImagesQueryHandler(IApplicationDbContext context)
    {
        _context = context;
    }

    public async Task<GetProductImagesResponseDto> Handle(GetProductImagesQuery request,
        CancellationToken cancellationToken)
    {
        var response = await _context.ProductImages
            .AsNoTracking()
            .Where(x => x.Id == request.Id)
            .ProjectToType<GetProductImagesResponseDto>()
            .FirstOrDefaultAsync(cancellationToken);

        return response ?? throw new NotFoundException(nameof(ProductImage), request.Id);
    }
}
