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 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);
}

View File

@ -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;
}
}

View File

@ -5,9 +5,12 @@ public record ProductBoughtIntegrationEvent : IntegrationEvent
public int ProductId { get; }
public int Units { get; }
public ProductBoughtIntegrationEvent(int productId, int units)
public decimal Price { get; }
public ProductBoughtIntegrationEvent(int productId, int units, decimal price)
{
ProductId = productId;
Units = units;
Price = price;
}
}