public async Task <PaymentDto> HandleAsync(GetPayment query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } return(_mapper.MapToWithNullPropagation <PaymentDto>(await _paymentsRepository.GetAsync(query.Id))); }
public async Task <IOperationResult> HandleAsync(IDeletePayment command, ICorrelationContext context) { var payment = await _paymentsRepository.GetAsync(command.Id); if (payment is null) { throw new BaristaException("payment_not_found", $"Could not find payment with ID '{command.Id}'"); } await _paymentsRepository.DeleteAsync(payment); await _paymentsRepository.SaveChanges(); await _busPublisher.Publish(new PaymentDeleted(command.Id)); return(OperationResult.Ok()); }
public async Task <IOperationResult> HandleAsync(IUpdatePayment command, ICorrelationContext context) { var payment = await _paymentsRepository.GetAsync(command.Id); if (payment is null) { throw new BaristaException("payment_not_found", $"Payment with ID '{command.Id}' was not found"); } await _userVerifier.AssertExists(command.UserId); payment.SetUserId(command.UserId); payment.SetAmount(command.Amount); payment.SetExternalId(command.ExternalId); payment.SetSource(command.Source); await _paymentsRepository.UpdateAsync(payment); await _paymentsRepository.SaveChanges(); await _busPublisher.Publish(new PaymentUpdated(payment)); return(OperationResult.Ok()); }