Skip to content

Commit

Permalink
Merge branch 'master' into 23-parser-for-list-ingredients-v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NaychiMin authored Oct 17, 2023
2 parents ea5dbbd + eb16e2c commit d23e91b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
22 changes: 20 additions & 2 deletions src/main/java/seedu/duke/command/DeleteDishCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
package seedu.duke.command;

import seedu.duke.data.Menu;
import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;

/**
* Deletes a menu item identified using it's last displayed index from the menu.
*/
public class DeleteDishCommand extends Command {

public static final String COMMAND_WORD = "delete";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the menu item identified by the index number used in the last menu listing.\n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";

/**
* Constructor for DeleteDishCommand
*
* @param index index of menu item to be deleted
*/
public DeleteDishCommand(int index) {
this.index = index;
}

@Override
public void execute(Menu menu, Ui ui) {

};
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);
}
}
15 changes: 10 additions & 5 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static Command parseCommand(Menu menu, String userInput) {
return new ListMenuCommand();
case ListIngredientCommand.COMMAND_WORD:
return prepareListIngredient(userInput);
/*case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(menu,userInput);*/
case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(userInput);
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
case AddDishCommand.COMMAND_WORD:
Expand Down Expand Up @@ -59,11 +59,16 @@ private static Command prepareListIngredient(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(userInput, DeleteDishCommand.COMMAND_WORD);
//return new DeleteDishCommand(listIndex);
return new IncorrectCommand("SHANICE DO YOUR WORK");
return new DeleteDishCommand(listIndex);
} catch (ParseException e) {
return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE);
} catch (NumberFormatException nfe) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/duke/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,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("Okies! " + menuItem + " deleted! :)");
public void showDeleteMessage(Dish selectedDish) {
showToUser("Okay! " + selectedDish.getName() + " is deleted! :)");
}


Expand Down

0 comments on commit d23e91b

Please sign in to comment.