public async Task <IActionResult> Buy([FromBody] BuyCurrencyRequest request) { await _mediator.Send(new BuyCurrencyCommand { UserId = request.UserId, AccountId = request.AccountId, CurrencyAccountId = request.CurrencyAccountId, Amount = request.Amount }); return(Ok()); }
public async Task <ActionResult <BuyCurrencyResponse> > BuyCurrency(BuyCurrencyRequest request) { try { _currencyController = _currencyControllerFactory.CreateCurrencyController(request.CurrencyCode.ToUpper()); return(StatusCode(StatusCodes.Status201Created, await _currencyController.BuyCurrency(request.UserId, request.Amount))); } catch (ArgumentException argumentException) { _logger.LogError(argumentException, "Invalid currency"); return(StatusCode(StatusCodes.Status400BadRequest, argumentException.Message)); } catch (Exception exception) { _logger.LogError(exception, "Unhandled exception"); return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message)); } }