diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 5441e6f..34137a5 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -630,9 +630,14 @@ public String digest(String productId) { public void addToCart(String productId) { if (currentAccount.getRole() == Role.CUSTOMER) { - Map cart = currentAccount.getCart(); - cart.put(getAvailableProductById(productId),1); - currentAccount.setCart(cart); + if (getProductById(productId).getAmount() > 0) { + Map cart = currentAccount.getCart(); + cart.put(getAvailableProductById(productId),1); + currentAccount.setCart(cart); + getProductById(productId).setAmount(getProductById(productId).getAmount() - 1); + } + else + System.out.println("not available"); } else System.out.println("invalid command"); diff --git a/src/main/java/view/Menu/GoodMenu.java b/src/main/java/view/Menu/GoodMenu.java index 118d5dd..11e4a26 100644 --- a/src/main/java/view/Menu/GoodMenu.java +++ b/src/main/java/view/Menu/GoodMenu.java @@ -128,8 +128,13 @@ public void show() { System.out.println("Compare Menu"); System.out.println("1.back"); String input = scanner.nextLine(); - for (String productAttribute : controller.compare(goodId, input)) { - System.out.println(productAttribute); + if (controller.getProductById(input) != null) { + for (String productAttribute : controller.compare(goodId, input)) { + System.out.println(productAttribute); + } + } + else { + System.out.println("invalid id"); } }