Add price to product bought event.

This commit is contained in:
Philipp Theyssen 2023-05-11 12:00:10 +02:00
parent b4b9e6c8d6
commit 3a15243e36
3 changed files with 11 additions and 4 deletions

View File

@ -31,7 +31,7 @@ public class OrderStatusChangedToPaidDomainEventHandler
var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString());
var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems 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( var orderStatusChangedToPaidIntegrationEvent = new OrderStatusChangedToPaidIntegrationEvent(
orderStatusChangedToPaidDomainEvent.OrderId, orderStatusChangedToPaidDomainEvent.OrderId,
@ -43,7 +43,8 @@ public class OrderStatusChangedToPaidDomainEventHandler
{ {
var productBoughtEvent = new ProductBoughtIntegrationEvent( var productBoughtEvent = new ProductBoughtIntegrationEvent(
orderStockItem.ProductId, orderStockItem.ProductId,
orderStockItem.Units orderStockItem.Units,
orderStockItem.Price
); );
await _orderingIntegrationEventService.AddAndSaveEventAsync(productBoughtEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(productBoughtEvent);
} }

View File

@ -22,9 +22,12 @@ public record OrderStockItem
public int ProductId { get; } public int ProductId { get; }
public int Units { 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; ProductId = productId;
Units = units; Units = units;
Price = price;
} }
} }

View File

@ -4,10 +4,13 @@ public record ProductBoughtIntegrationEvent : IntegrationEvent
{ {
public int ProductId { get; } public int ProductId { get; }
public int Units { 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; ProductId = productId;
Units = units; Units = units;
Price = price;
} }
} }