From 3a15243e36b627820b773f29db804780ec1679bb Mon Sep 17 00:00:00 2001 From: Philipp Theyssen Date: Thu, 11 May 2023 12:00:10 +0200 Subject: [PATCH] Add price to product bought event. --- .../OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs | 5 +++-- ...OrderStatusChangedToAwaitingValidationIntegrationEvent.cs | 5 ++++- .../Events/ProductBoughtIntegrationEvent.cs | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs index 16e64d2a6..0163b6118 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs @@ -31,7 +31,7 @@ public class OrderStatusChangedToPaidDomainEventHandler var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems - .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); + .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits(), orderItem.GetUnitPrice())); var orderStatusChangedToPaidIntegrationEvent = new OrderStatusChangedToPaidIntegrationEvent( orderStatusChangedToPaidDomainEvent.OrderId, @@ -43,7 +43,8 @@ public class OrderStatusChangedToPaidDomainEventHandler { var productBoughtEvent = new ProductBoughtIntegrationEvent( orderStockItem.ProductId, - orderStockItem.Units + orderStockItem.Units, + orderStockItem.Price ); await _orderingIntegrationEventService.AddAndSaveEventAsync(productBoughtEvent); } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs index 1f7ef35e2..3153c08e5 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs @@ -22,9 +22,12 @@ public record OrderStockItem public int ProductId { get; } public int Units { get; } - public OrderStockItem(int productId, int units) + public decimal Price; + + public OrderStockItem(int productId, int units, decimal price = Decimal.Zero) { ProductId = productId; Units = units; + Price = price; } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/ProductBoughtIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/ProductBoughtIntegrationEvent.cs index 6b7e0fd71..b4097e9c2 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/ProductBoughtIntegrationEvent.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/ProductBoughtIntegrationEvent.cs @@ -4,10 +4,13 @@ public record ProductBoughtIntegrationEvent : IntegrationEvent { public int ProductId { get; } public int Units { get; } + + public decimal Price { get; } - public ProductBoughtIntegrationEvent(int productId, int units) + public ProductBoughtIntegrationEvent(int productId, int units, decimal price) { ProductId = productId; Units = units; + Price = price; } } \ No newline at end of file