Skip to content

Commit 2f94499

Browse files
committed
feat: update EcommerceSystem to use final fields and improve order handling
1 parent 50680f2 commit 2f94499

File tree

1 file changed

+8
-3
lines changed
  • lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce

1 file changed

+8
-3
lines changed

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/EcommerceSystem.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import java.util.UUID;
66

77
public class EcommerceSystem {
8-
private Map<String, Product> products;
9-
private Map<String, Order> orders;
8+
private final Map<String, Product> products;
9+
private final Map<String, Order> orders;
1010

1111
public EcommerceSystem() {
1212
products = new HashMap<>();
@@ -19,6 +19,8 @@ public void addProduct(String productId, String name) {
1919

2020
public String placeOrder(String productId, int quantity) {
2121
Product product = products.get(productId);
22+
if (product == null) {
23+
}
2224
String orderId = UUID.randomUUID().toString();
2325
orders.put(orderId, new Order(orderId, product, quantity));
2426
return orderId;
@@ -28,8 +30,11 @@ public void cancelOrder(String orderId) {
2830
orders.remove(orderId);
2931
}
3032

31-
public String checkOrderStatus(String orderId) {
33+
public String checkOrderStatus(String orderId) throws IllegalArgumentException {
3234
Order order = orders.get(orderId);
35+
if (order == null) {
36+
return "Order not found";
37+
}
3338
return "Order ID: "
3439
+ orderId
3540
+ ", Product: "

0 commit comments

Comments
 (0)