namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract;
public class GetUserContractQueryHandler : IRequestHandler<GetUserContractQuery, GetUserContractResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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