namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetFactorDetails;
public class GetFactorDetailsQueryHandler : IRequestHandler<GetFactorDetailsQuery, GetFactorDetailsResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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