using Netina.Domain.Entities.Accounting; namespace Netina.Repository.Handlers.Accounting; public class GetPaymentQueryHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler { public async Task Handle(GetPaymentQuery request, CancellationToken cancellationToken) { PaymentSDto? payment = null; if (request.Authority != null) { payment = await repositoryWrapper.SetRepository() .TableNoTracking .Where(p => p.Authority == request.Authority) .Select(PaymentMapper.ProjectToSDto) .FirstOrDefaultAsync(cancellationToken); } else { if (request.Id == default) throw new Exception("Id is null"); payment = await repositoryWrapper.SetRepository() .TableNoTracking .Where(p => p.Id == request.Id) .Select(PaymentMapper.ProjectToSDto) .FirstOrDefaultAsync(cancellationToken); } if (payment == null) throw new AppException("Payment not found !", ApiResultStatusCode.NotFound); return payment; } }