Skip to content

Commit 7b40920

Browse files
committed
amazon: added order id
1 parent 42cbf08 commit 7b40920

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/com/lld/amazon/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private static void test1(PricingService pricingService, OrderService orderServi
5959

6060
Payment payment = orderService.pay(order);
6161
System.out.println("Payment status: " + payment.getPaymentStatus());
62+
System.out.println("Order placed with order id: " + order.getId());
6263
}
6364

6465
private static Product getProduct1(PricingService pricingService) throws PricingException {

src/com/lld/amazon/model/Order.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22

33
import java.util.Collections;
44
import java.util.List;
5+
import java.util.UUID;
56

67
public class Order {
8+
private final String id;
79
private List<QuantifiedCartOrOrder> orders;
810
// Each item in the order can have its own delivery ETA
911
private List<OrderItemDelivery> orderItemDeliveries;
1012
private Payment payment;
1113

1214
public Order(List<QuantifiedCartOrOrder> orders, List<OrderItemDelivery> orderItemDeliveries, Payment payment) {
15+
this.id = UUID.randomUUID().toString();
1316
this.orders = orders;
1417
this.orderItemDeliveries = orderItemDeliveries;
1518
this.payment = payment;
1619
}
1720

21+
public String getId() {
22+
return id;
23+
}
24+
1825
public Money getOrderTotal() {
1926
return this.payment.getTotalAmount();
2027
}

src/com/lld/amazon/service/impl/OrderServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public Payment pay(Order order) {
4141
// Order service should talk to payment service here
4242
// Depending on the result, mark success or failure
4343
order.getPayment().markPaymentSuccess();
44+
// Update order state here through state machine mechanism
4445
return order.getPayment();
4546
}
4647
}

0 commit comments

Comments
 (0)