From 812654327335924346f337a4102942a40b05df4e Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 01:44:54 +0800 Subject: [PATCH 1/7] Edit delete message --- src/main/java/seedu/duke/ui/Ui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java index 61d84f6866..9dc129ec49 100644 --- a/src/main/java/seedu/duke/ui/Ui.java +++ b/src/main/java/seedu/duke/ui/Ui.java @@ -30,7 +30,7 @@ public void showGoodbye() { * @param menuItem String of menu item deleted */ public void showDeleteMessage(String menuItem) { - showToUser("Okies! " + menuItem + " deleted! :)"); + showToUser("Okay! " + menuItem + " is deleted! :)"); } /** Shows messages(s) to the user **/ From ddd3d5049a361d1bc8b66e1fc77f7b4ea24ed638 Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 01:46:09 +0800 Subject: [PATCH 2/7] Update delete command --- .../java/seedu/duke/command/DeleteDishCommand.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java index fe3932cbaa..48fea6ab9d 100644 --- a/src/main/java/seedu/duke/command/DeleteDishCommand.java +++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java @@ -8,8 +8,20 @@ */ public class DeleteDishCommand extends Command { + private int dishIndex; + + /** + * Constructor for DeleteDishCommand + * + * @param index index of menu item to be deleted + */ + public DeleteDishCommand(int index) { + this.dishIndex = index; + } + @Override public void execute(Menu menu, Ui ui) { - + menu.remove(dishIndex); + ui.showDeleteMessage(menu.getDish(dishIndex).toString()); }; } From 5e69f2317cb5536d4b0bbad556082b7c831439a8 Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 14:26:03 +0800 Subject: [PATCH 3/7] Rename remove to removeDish method --- src/main/java/seedu/duke/command/DeleteDishCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java index 48fea6ab9d..a5e7320745 100644 --- a/src/main/java/seedu/duke/command/DeleteDishCommand.java +++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java @@ -21,7 +21,7 @@ public DeleteDishCommand(int index) { @Override public void execute(Menu menu, Ui ui) { - menu.remove(dishIndex); + menu.removeDish(dishIndex); ui.showDeleteMessage(menu.getDish(dishIndex).toString()); }; } From be50d359eeb512d129d052773bddfd07c2982b9f Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 15:09:47 +0800 Subject: [PATCH 4/7] Handle invalid index error --- .../seedu/duke/command/DeleteDishCommand.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java index 01e0fcaf86..144f443632 100644 --- a/src/main/java/seedu/duke/command/DeleteDishCommand.java +++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java @@ -1,6 +1,8 @@ package seedu.duke.command; import seedu.duke.data.Menu; +import seedu.duke.data.dish.Dish; +import seedu.duke.data.dish.Ingredient; import seedu.duke.ui.Ui; /** @@ -14,20 +16,23 @@ public class DeleteDishCommand extends Command { + "Parameters: INDEX\n" + "Example: " + COMMAND_WORD + " 1"; - private int dishIndex; - /** * Constructor for DeleteDishCommand * * @param index index of menu item to be deleted */ public DeleteDishCommand(int index) { - this.dishIndex = index; + this.index = index; } @Override public void execute(Menu menu, Ui ui) { - menu.removeDish(dishIndex); - ui.showDeleteMessage(menu.getDish(dishIndex).toString()); + Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX); + if (selectedDish != null) { + ui.showDeleteMessage(selectedDish); + } else { + ui.showToUser("Please select a valid dish index :)"); + } + menu.removeDish(index); } } From 411253bc7049f64567ed3785d19fc9e8d93c4dbb Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 15:10:27 +0800 Subject: [PATCH 5/7] Reformat printed string --- src/main/java/seedu/duke/ui/Ui.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java index d6be50e9a6..5e8d546e2f 100644 --- a/src/main/java/seedu/duke/ui/Ui.java +++ b/src/main/java/seedu/duke/ui/Ui.java @@ -73,10 +73,10 @@ public void printAddDishMessage(Dish dish) { /** * Shows delete message to user * - * @param menuItem String of menu item deleted + * @param selectedDish Dish to be deleted */ - public void showDeleteMessage(String menuItem) { - showToUser("Okay! " + menuItem + " is deleted! :)"); + public void showDeleteMessage(Dish selectedDish) { + showToUser("Okay! " + selectedDish.getName() + " is deleted! :)"); } From 2e861f26e20a182639268add85bec7b82792038c Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 15:10:58 +0800 Subject: [PATCH 6/7] Fixes #22 Implement parser support for deleting a dish --- src/main/java/seedu/duke/parser/Parser.java | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java index 345ad48895..34e44a2633 100644 --- a/src/main/java/seedu/duke/parser/Parser.java +++ b/src/main/java/seedu/duke/parser/Parser.java @@ -28,10 +28,10 @@ public static Command parseCommand(Menu menu, String userInput) { switch (command[0].toLowerCase()) { case ListMenuCommand.COMMAND_WORD: return new ListMenuCommand(); - /*case ListIngredientCommand.COMMAND_WORD: - return prepareListIngredient(menu,userInput); +// case ListIngredientCommand.COMMAND_WORD: +// return prepareListIngredient(menu,userInput); case DeleteDishCommand.COMMAND_WORD: - return prepareDelete(menu,userInput);*/ + return prepareDelete(userInput); case ExitCommand.COMMAND_WORD: return new ExitCommand(); case AddDishCommand.COMMAND_WORD: @@ -51,7 +51,7 @@ public static Command parseCommand(Menu menu, String userInput) { */ private static Command prepareListIngredient(Menu menu, String userInput) { try { - final int listIndex = parseArgsAsDisplayedIndex(menu ,userInput, ListIngredientCommand.COMMAND_WORD); + final int listIndex = parseArgsAsDisplayedIndex(userInput, ListIngredientCommand.COMMAND_WORD); //return new ListIngredientCommand(Menu menu, listIndex); return new IncorrectCommand("NAYCHI DO YOUR WORK"); } catch (ParseException e) { @@ -61,11 +61,16 @@ private static Command prepareListIngredient(Menu menu, String userInput) { } } - private static Command prepareDelete(Menu menu, String userInput) { + /** + * Parses arguments in the context of the Delete command. + * + * @param userInput Input from the user + * @return Command to be executed + */ + private static Command prepareDelete(String userInput) { try { - final int listIndex = parseArgsAsDisplayedIndex(menu, userInput, DeleteDishCommand.COMMAND_WORD); - //return new DeleteDishCommand(listIndex); - return new IncorrectCommand("SHANICE DO YOUR WORK"); + final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD); + return new DeleteDishCommand(listIndex); } catch (ParseException e) { return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE); } catch (NumberFormatException nfe) { @@ -78,15 +83,13 @@ private static Command prepareDelete(Menu menu, String userInput) { * * @param userInput arguments string to parse as index number * @param command expected String name of the command called - * @param menu The arraylist object created that stores current dishes * @return the parsed index number * @throws ParseException if no region of the args string could be found for the index * @throws NumberFormatException the args string region is not a valid number */ - private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command) + private static int parseArgsAsDisplayedIndex(String userInput, String command) throws ParseException, NumberFormatException { String formattedString = userInput.replace(command, "").trim(); - int listIndex = Integer.parseInt(formattedString); - return listIndex; + return Integer.parseInt(formattedString); } } From e94d49fcda0fa69ee9d80bab03b075c94b7c80e5 Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Tue, 17 Oct 2023 15:18:50 +0800 Subject: [PATCH 7/7] Improve code standard Fixes #22 --- src/main/java/seedu/duke/command/DeleteDishCommand.java | 1 - src/main/java/seedu/duke/parser/Parser.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java index 144f443632..265fb3ca46 100644 --- a/src/main/java/seedu/duke/command/DeleteDishCommand.java +++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java @@ -2,7 +2,6 @@ import seedu.duke.data.Menu; import seedu.duke.data.dish.Dish; -import seedu.duke.data.dish.Ingredient; import seedu.duke.ui.Ui; /** diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java index 34e44a2633..a5309dbbb0 100644 --- a/src/main/java/seedu/duke/parser/Parser.java +++ b/src/main/java/seedu/duke/parser/Parser.java @@ -28,8 +28,8 @@ public static Command parseCommand(Menu menu, String userInput) { switch (command[0].toLowerCase()) { case ListMenuCommand.COMMAND_WORD: return new ListMenuCommand(); -// case ListIngredientCommand.COMMAND_WORD: -// return prepareListIngredient(menu,userInput); + //case ListIngredientCommand.COMMAND_WORD: + //return prepareListIngredient(menu,userInput); case DeleteDishCommand.COMMAND_WORD: return prepareDelete(userInput); case ExitCommand.COMMAND_WORD: