diff --git a/bounded-contexts/java/src/main/java/p1/myshop/entities/Quantity.java b/bounded-contexts/java/src/main/java/p1/myshop/entities/Quantity.java index 63e5d71..87a98e9 100644 --- a/bounded-contexts/java/src/main/java/p1/myshop/entities/Quantity.java +++ b/bounded-contexts/java/src/main/java/p1/myshop/entities/Quantity.java @@ -1,4 +1,14 @@ package p1.myshop.entities; public class Quantity { + + int value; + + Quantity(int value) { + this.value = value; + } + + public int toInt() { + return value; + } } diff --git a/bounded-contexts/java/src/main/java/p1/myshop/services/shipping/DeliveryService.java b/bounded-contexts/java/src/main/java/p1/myshop/services/shipping/DeliveryService.java index afb1116..3607b8a 100644 --- a/bounded-contexts/java/src/main/java/p1/myshop/services/shipping/DeliveryService.java +++ b/bounded-contexts/java/src/main/java/p1/myshop/services/shipping/DeliveryService.java @@ -14,9 +14,7 @@ public DeliveryService(CatalogService catalogService) { public double calculateOrderWeight(Cart cart) { return cart.items().stream() - .map(CartItem::itemId) - .map(catalogService::loadItem) - .mapToDouble(HasWeight::weight) + .mapToDouble(cartItem -> cartItem.quantity.toInt() * catalogService.loadItem(cartItem.itemId).weight()) .sum(); } }