namespace CMSMicroservice.Application.ProductGalleriesCQ.Queries.GetProductGalleries;
public class GetProductGallerysQueryHandler : IRequestHandler<GetProductGalleriesQuery, GetProductGallerysResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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