diff --git a/src/Services/Orders/Distribt.Services.Orders/Services/CreateOrderService.cs b/src/Services/Orders/Distribt.Services.Orders/Services/CreateOrderService.cs index 0375104..79088c0 100644 --- a/src/Services/Orders/Distribt.Services.Orders/Services/CreateOrderService.cs +++ b/src/Services/Orders/Distribt.Services.Orders/Services/CreateOrderService.cs @@ -36,10 +36,10 @@ public async Task> Execute(CreateOrderRequest create .Async() //On a real scenario: //validate orders - //validate fraud check + .Bind(x=> ValidateFraudCheck(x, cancellationToken)) .Bind(x => SaveOrder(x, cancellationToken)) - .Then(x => MapToOrderResponse(x, cancellationToken) - .Bind(or => PublishDomainEvent(or, cancellationToken))) + .Then(x => MapToOrderResponse(x) + .Bind(PublishDomainEvent)) .Map(x => new CreateOrderResponse(x.Id, $"order/getorderstatus/{x.Id}")); } @@ -60,12 +60,11 @@ private async Task> SaveOrder(OrderDetails orderDetails, Ca return orderDetails; } - private async Task> MapToOrderResponse(OrderDetails orderDetails, - CancellationToken cancellationToken) + private async Task> MapToOrderResponse(OrderDetails orderDetails) { var products = await orderDetails.Products .SelectAsync(async p => new ProductQuantityName(p.ProductId, p.Quantity, - await _productNameService.GetProductName(p.ProductId, cancellationToken))); + await _productNameService.GetProductName(p.ProductId))); OrderResponse orderResponse = new OrderResponse(orderDetails.Id, orderDetails.Status.ToString(), @@ -73,10 +72,16 @@ private async Task> MapToOrderResponse(OrderDetails orderD return orderResponse; } - private async Task> PublishDomainEvent(OrderResponse orderResponse, - CancellationToken cancellationToken) + private async Task> PublishDomainEvent(OrderResponse orderResponse) { - await _domainMessagePublisher.Publish(orderResponse, routingKey: "order", cancellationToken: cancellationToken); + await _domainMessagePublisher.Publish(orderResponse, routingKey: "order"); return orderResponse.OrderId; } + + private async Task> ValidateFraudCheck(OrderDetails orderDetails, + CancellationToken cancellationToken) + { + //Simulation of fraud check validation + return orderDetails; + } } \ No newline at end of file