namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public class GetContractQueryHandler : IRequestHandler<GetContractQuery, GetContractResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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