diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 6eb45ec045d..bf7e93e11a5 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -247,6 +247,64 @@ The following sequence diagram shows how eat recipe operation works when `execut _{Explain here how the data archiving feature will be implemented}_ +### Delete recipe feature + +#### Implementation +This feature allows users to delete the recipes they have eaten in the calorie tracker. + +Substitutability is used in Command and Parser: +* `DeleteRecipeCommand` extends `Command` +* `DeleteRecipeCommandParser` implements `Parser` + +Given below is an example usage scenario and how the mechanism behaves at each step. + +Step 1: +User inputs the delete recipe command to delete recipe from the recipe list. + +Step 2: +After successful parsing of user input, the `DeleteRecipeCommand#execute(Model model)` method is called. + +Step 3: +The recipe that the user has specified by using index will be deleted from the recipe list. + +Step 4: +After the successful deleting of recipes, a `CommandResult` object is instantiated and returned to `LogicManager`. + +The following sequence diagram shows how eat recipe operation works when `execute(deleteR 1)` API call: + +![DeleteRecipeSequence](images/DeleteRecipeSequence.png) + +#### Design consideration: +##### Aspect 1: Concern while adding a new feature +* Workflow must be consistent with other deleting commands e.g. delete ingredient and delete consumption. + +### List Recipe Feature + +#### Implementation +This feature allows user to list out all the recipes that was saved. + +Substitutability is used in Command: +* `DeleteRecipeCommand` extends `Command` + +Given below is an example usage scenario and how the mechanism behaves at each step. + +Step 1: +User inputs the list recipe command to show all recipes from the recipe list. + +Step 2: +After successful parsing of user input, the `ListRecipeCommand#execute(Model model)` method is called. + +Step 3: +After successfully generating a list of recipes, a `CommandResult` object is instantiated and returned to `LogicManager`. + +The following sequence diagram shows how eat recipe operation works when `execute(eatR 1)` API call: + +![ListRecipeSequence](images/ListRecipesSequence.png) + +#### Design consideration: +##### Aspect 1: Concern while adding a new feature +* Workflow must be consistent with other listing commands e.g. fridge and calories. + ### Add Ingredient feature #### Implementation diff --git a/docs/diagrams/DeleteRecipeSequence.puml b/docs/diagrams/DeleteRecipeSequence.puml new file mode 100644 index 00000000000..2d491098758 --- /dev/null +++ b/docs/diagrams/DeleteRecipeSequence.puml @@ -0,0 +1,86 @@ +@startuml +!include style.puml + +box Logic LOGIC_COLOR_T1 +participant ":LogicManager" as LogicManager LOGIC_COLOR +participant ":WishfulShrinkingParser" as WishfulShrinkingParser LOGIC_COLOR +participant ":DeleteRecipeCommandParser" as DeleteRecipeCommandParser LOGIC_COLOR +participant "d:DeleteRecipeCommand" as DeleteRecipeCommand LOGIC_COLOR +participant ":CommandResult" as CommandResult LOGIC_COLOR +end box + +box Model MODEL_COLOR_T1 +participant ":Model" as Model MODEL_COLOR +participant ":WishfulShrinking" as WishfulShrinking MODEL_COLOR +participant ":UniqueRecipeList" as UniqueRecipeList MODEL_COLOR +end box + +[-> LogicManager : execute("deleteR 1") +activate LogicManager + +LogicManager -> WishfulShrinkingParser : parseCommand("deleteR 1") +activate WishfulShrinkingParser + +create DeleteRecipeCommandParser +WishfulShrinkingParser -> DeleteRecipeCommandParser +activate DeleteRecipeCommandParser + +DeleteRecipeCommandParser --> WishfulShrinkingParser +deactivate DeleteRecipeCommandParser + +WishfulShrinkingParser -> DeleteRecipeCommandParser : parse("1") +activate DeleteRecipeCommandParser + +create DeleteRecipeCommand +DeleteRecipeCommandParser -> DeleteRecipeCommand +activate DeleteRecipeCommand + +DeleteRecipeCommand --> DeleteRecipeCommandParser : command +deactivate DeleteRecipeCommand + +DeleteRecipeCommandParser --> WishfulShrinkingParser : command +deactivate DeleteRecipeCommandParser +'Hidden arrow to position the destroy marker below the end of the activation bar. +DeleteRecipeCommandParser -[hidden]-> WishfulShrinkingParser +destroy DeleteRecipeCommandParser + +WishfulShrinkingParser --> LogicManager : command +deactivate WishfulShrinkingParser + +LogicManager -> DeleteRecipeCommand : execute() +activate DeleteRecipeCommand + +DeleteCommand -> Model : getFilteredRecipeList() +activate Model + +Model -> WishfulShrinking : removeRecipe(key) +activate WishfulShrinking + +WishfulShrinking -> UniqueRecipeList : remove(toRemove) +activate UniqueRecipeList + +UniqueRecipeList -> WishfulShrinking +deactivate UniqueRecipeList + +WishfulShrinking -> Model +deactivate WishfulShrinking + +Model -> DeleteRecipeCommand +deactivate Model + +Model --> DeleteRecipeCommand +deactivate Model + +create CommandResult +DeleteRecipeCommand -> CommandResult +activate CommandResult + +CommandResult --> DeleteRecipeCommand +deactivate CommandResult + +DeleteRecipeCommand --> LogicManager : result +deactivate DeleteRecipeCommand + +[<--LogicManager +deactivate LogicManager +@enduml diff --git a/docs/diagrams/ListRecipesSequence.puml b/docs/diagrams/ListRecipesSequence.puml new file mode 100644 index 00000000000..2631cd5f936 --- /dev/null +++ b/docs/diagrams/ListRecipesSequence.puml @@ -0,0 +1,68 @@ +@startuml +!include style.puml + +box Logic LOGIC_COLOR_T1 +participant ":LogicManager" as LogicManager LOGIC_COLOR +participant ":WishfulShrinkingParser" as WishfulShrinkingParser LOGIC_COLOR +participant "l:ListRecipesCommand" as ListRecipesCommand LOGIC_COLOR +participant ":CommandResult" as CommandResult LOGIC_COLOR +end box + +box Model MODEL_COLOR_T1 +participant ":Model" as Model MODEL_COLOR +participant ":WishfulShrinking" as WishfulShrinking MODEL_COLOR +end box + +[-> LogicManager : execute("recipes") +activate LogicManager + +LogicManager -> WishfulShrinkingParser : parseCommand("recipes") +activate WishfulShrinkingParser + +create ListRecipesCommand +WishfulShrinkingParser -> ListRecipesCommand +activate ListRecipesCommand + +ListRecipesCommand --> WishfulShrinkingParser +deactivate ListRecipesCommand + +WishfulShrinkingParser --> LogicManager : command +deactivate WishfulShrinkingParser + +LogicManager -> ListRecipesCommand : execute() +activate ListRecipesCommand + +ListRecipesCommand -> Model : updateFilteredRecipeList() +activate Model + +Model -> WishfulShrinking : getRecipeList() +activate WishfulShrinking + +WishfulShrinking -> UniqueRecipeList : asUnmodifiableObservableList() +activate UniqueRecipeList + +UniqueRecipeList -> WishfulShrinking +deactivate UniqueRecipeList + +WishfulShrinking -> Model +deactivate WishfulShrinking + +Model -> ListRecipesCommand +deactivate Model + +Model --> ListRRecipesCommand +deactivate Model + +create CommandResult +ListRecipesCommand -> CommandResult +activate CommandResult + +CommandResult --> ListRecipesCommand +deactivate CommandResult + +ListRecipesCommand --> LogicManager : result +deactivate ListRecipesCommand + +[<--LogicManager +deactivate LogicManager +@enduml diff --git a/docs/images/DeleteRecipeSequence.png b/docs/images/DeleteRecipeSequence.png new file mode 100644 index 00000000000..bfec7521a27 Binary files /dev/null and b/docs/images/DeleteRecipeSequence.png differ diff --git a/docs/images/ListRecipesSequence.png b/docs/images/ListRecipesSequence.png new file mode 100644 index 00000000000..fcc25408857 Binary files /dev/null and b/docs/images/ListRecipesSequence.png differ diff --git a/src/main/java/seedu/address/logic/commands/DeleteRecipeCommand.java b/src/main/java/seedu/address/logic/commands/DeleteRecipeCommand.java index 23c7525639a..c801dd21ffd 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteRecipeCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteRecipeCommand.java @@ -3,6 +3,8 @@ import static java.util.Objects.requireNonNull; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; @@ -24,6 +26,8 @@ public class DeleteRecipeCommand extends Command { public static final String MESSAGE_DELETE_RECIPE_SUCCESS = "Deleted Recipe: %1$s"; + private static Logger logger = Logger.getLogger("DeleteLogger"); + private final Index toDelete; public DeleteRecipeCommand(Index toDelete) { @@ -32,6 +36,7 @@ public DeleteRecipeCommand(Index toDelete) { @Override public CommandResult execute(Model model) throws CommandException { + logger.log(Level.INFO, "going to start deleting"); requireNonNull(model); List lastShownList = model.getFilteredRecipeList(); @@ -41,6 +46,7 @@ public CommandResult execute(Model model) throws CommandException { Recipe recipeToDelete = lastShownList.get(toDelete.getZeroBased()); model.deleteRecipe(recipeToDelete); + logger.log(Level.INFO, "end of deleting"); return new CommandResult(String.format(MESSAGE_DELETE_RECIPE_SUCCESS, recipeToDelete)); }