Skip to content

Feat: Adds-Changes to Lesson14 .Java files for Nile Jackson #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@ 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 1 not found");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the productId isn't 1? The message should change.

}
String orderId = UUID.randomUUID().toString();
orders.put(orderId, new Order(orderId, product, quantity));
return orderId;
}

public void cancelOrder(String orderId) {
public void cancelOrder(String orderId) throws OrderNotFoundException {
Order order = orders.get(orderId);
try {
if (order == null) throw new OrderNotFoundException("No Such order exists");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not in the requirements for this assignment.

} catch (OrderNotFoundException e) {
System.out.println(" order does not exist");
}
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 1 not found");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same message as above but for orderId

return "Order ID: "
+ orderId
+ ", Product: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@

package com.codedifferently.lesson14.ecommerce;

class OrderNotFoundException {}
class OrderNotFoundException extends RuntimeException {

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