36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Netina.Domain.Entities.Accounting;
|
|
|
|
namespace Netina.Repository.Handlers.Accounting;
|
|
|
|
public class GetPaymentQueryHandler(IRepositoryWrapper repositoryWrapper)
|
|
: IRequestHandler<GetPaymentQuery, PaymentSDto>
|
|
{
|
|
public async Task<PaymentSDto> Handle(GetPaymentQuery request, CancellationToken cancellationToken)
|
|
{
|
|
PaymentSDto? payment = null;
|
|
if (request.Authority != null)
|
|
{
|
|
payment = await repositoryWrapper.SetRepository<Payment>()
|
|
.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<Payment>()
|
|
.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;
|
|
}
|
|
} |