public async Task <IActionResult> CreateOrderAsync( [FromBody] CreateOrderCommand createOrderCommand, [FromHeader(Name = "x-request-id")] string requestId, [FromHeader(Name = "jwt-extracted-sub")] string customerId) { _logger.LogInformation("CreateOrderAsync: {requestId}", requestId); var hasRequestGuid = Guid.TryParse(requestId, out Guid requestIdGuid) && requestIdGuid != Guid.Empty; if (!hasRequestGuid) { return(BadRequest()); } var hasCustomerGuid = Guid.TryParse(customerId, out Guid customerIdGuid) && customerIdGuid != Guid.Empty; if (!hasCustomerGuid) { return(BadRequest()); } createOrderCommand.OrderId = requestIdGuid; createOrderCommand.CustomerId = customerIdGuid; var requestCreateOrder = new IdempotentCommand <CreateOrderCommand, bool>(createOrderCommand, requestIdGuid); var result = await _mediator.Send(requestCreateOrder); if (!result) { return(BadRequest()); } return(Ok(new { OrderId = requestCreateOrder.Command.OrderId })); }
public async Task <IActionResult> CreateOrderAsync([FromBody] CreateOrderCommand createOrderCommand, [FromHeader(Name = "x-requestid")] string requestId) { _logger.LogInformation("CreateOrderAsync: {requestId}", requestId); var hasRequestGuid = Guid.TryParse(requestId, out Guid requestIdGuid) && requestIdGuid != Guid.Empty; if (!hasRequestGuid) { return(BadRequest()); } var requestCreateOrder = new IdempotentCommand <CreateOrderCommand, bool>(createOrderCommand, requestIdGuid); var result = await _mediator.Send(requestCreateOrder); if (!result) { return(BadRequest()); } return(Ok()); }