Skip to content

Commit

Permalink
feat: added lesson_14's solutions for Chelsea
Browse files Browse the repository at this point in the history
  • Loading branch information
Cogbonnia committed Oct 28, 2024
1 parent 6185a38 commit 158c8a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public void addProduct(String productId, String name) {
products.put(productId, new Product(productId, name));
}

public String placeOrder(String productId, int quantity) {
public String placeOrder(String productId, int quantity) throws ProductNotFoundException {
Product product = products.get(productId);
if (product == null) {
throw new ProductNotFoundException("Product with ID " + productId + " not found");
}
String orderId = UUID.randomUUID().toString();
orders.put(orderId, new Order(orderId, product, quantity));
return orderId;
Expand All @@ -28,8 +31,11 @@ public void cancelOrder(String orderId) {
orders.remove(orderId);
}

public String checkOrderStatus(String orderId) {
public String checkOrderStatus(String orderId) throws OrderNotFoundException {
Order order = orders.get(orderId);
if (order == null) {
throw new OrderNotFoundException("Order with ID " + orderId + " not found");
}
return "Order ID: "
+ orderId
+ ", Product: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

package com.codedifferently.lesson14.ecommerce;

class OrderNotFoundException {}
class OrderNotFoundException extends Exception {
public OrderNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

package com.codedifferently.lesson14.ecommerce;

class ProductNotFoundException {}
class ProductNotFoundException extends Exception {
public ProductNotFoundException(String message) {
super(message);
}
}

0 comments on commit 158c8a7

Please sign in to comment.