Api/Netina.Repository/Handlers/Accounting/GetPaymentQueryHandler.cs

36 lines
1.2 KiB
C#
Raw Normal View History

2024-08-09 21:55:16 +03:30
using Netina.Domain.Entities.Accounting;
2024-04-16 20:01:34 +03:30
namespace Netina.Repository.Handlers.Accounting;
2024-08-09 21:55:16 +03:30
public class GetPaymentQueryHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<GetPaymentQuery, PaymentSDto>
{
public async Task<PaymentSDto> Handle(GetPaymentQuery request, CancellationToken cancellationToken)
{
PaymentSDto? payment = null;
if (request.Authority != null)
{
2024-08-09 21:55:16 +03:30
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");
2024-08-09 21:55:16 +03:30
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;
}
}