namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetTransactions;
public class GetTransactionsQueryHandler : IRequestHandler<GetTransactionsQuery, GetTransactionsResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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