namespace CMSMicroservice.Application.ProductCategoryCQ.Queries.GetProductCategory;
public class GetProductCategoryQueryHandler : IRequestHandler<GetProductCategoryQuery, GetProductCategoryResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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