Skip to content

Commit

Permalink
Merge pull request #115 from beatricetay/planning-feature-list
Browse files Browse the repository at this point in the history
More commands for planned recipes
  • Loading branch information
tharshita authored Apr 1, 2020
2 parents fed6f24 + 9ee6b9e commit 32ab8e9
Show file tree
Hide file tree
Showing 38 changed files with 681 additions and 322 deletions.
23 changes: 6 additions & 17 deletions data/addressbook.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
{
"recipes" : [ {
"name" : "Barley Pilaf",
"time" : "50",
"isFavourite" : true,
"grains" : [ "0.5cup, small pieces of broken spaghetti" ],
"vegetables" : [ "2.0tbsp, chives (chopped)", "50.0g, small onion (chopped)" ],
"proteins" : [ "2.5cup, low-sodium chicken broth" ],
"fruits" : [ ],
"others" : [ "1.0cup, hulled barley", "10.0g, Salt & Pepper", "1.0tbsp, unsalted butter" ],
"steps" : [ "Melt butter in saucepan over medium heat. Add onion and cook until soft and light golden brown.", "Add barley and stir until grains are coated in butter.", "Add broth and 0.5 tsp salt, bring to a boil.", "Reduce heat to medium low, cover, and simmer for 20mins.", "Uncover and quickly stir in spaghetti. Cover and continue to simmer, stirring occasionally.", "Once most liquid is absorbed and barley and spaghetti are tender, remove from hit and let sit.", "Season to taste with salt and pepper and sprinkle with chopped chives." ],
"goals" : [ "Wholesome Wholemeal" ]
}, {
"name" : "Asian BBQ Chicken",
"name" : "Asian BBQ Chicken 2",
"time" : "15",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "1.0tbsp, garlic & ginger (finely chopped)" ],
"proteins" : [ "100.0g, chicken breast" ],
"fruits" : [ ],
"others" : [ "2.0tbsp, char siew sauce", "1.0tsp, honey", "1.0tsp, rice vinegar", "1.0tsp, Salt & pepper", "0.5tsp, sesame oil" ],
"steps" : [ "In a bowl, mix all the ingredients to create marinade. Mix the chicken with the marinade.", "Pan sear the chicken from both sides.", "Serve with rice." ],
"others" : [ "2.0tbsp, char siew sauce", "1.0tsp, honey", "1.0tsp, rice vinegar", "1.0tsp, Salt & pepper", "0.5tsp, sesame oil", "50.0g, sugarspiceeverythingnice" ],
"steps" : [ "In a bowl, mix all the ingredients to create marinade. Mix the chicken with the marinade.", "Pan sear the chicken from both sides.", "edited step 3", "hi" ],
"goals" : [ "Bulk like the Hulk" ]
}, {
"name" : "Sweet and Sour Chicken",
"name" : "Sweet and Sour Chicken 2",
"time" : "20",
"isFavourite" : false,
"grains" : [ ],
Expand All @@ -44,8 +33,8 @@
"steps" : [ "Heat oil in wok over medium heat. Add ginger and garlic and cook for 20 seconds.", "Add carrot and stir-fry for 30 seconds - oil should turn orange colour. Add in daikon, turn up heat to high and stir-fry for another 30 seconds.", "Add shaoxing wine, oyster sauce, white pepper, sesame oil, salt, water, and white parts of the scallions. Stir to combine, cover, turn down heat to medium. Simmer for 5-8 minutes until tender.", "Uncover, add in rest of the scallions and mix everything well. When dailon is translucent and tender, the dish is done." ],
"goals" : [ "Herbivore" ]
}, {
"name" : "Chinese Tomato Egg Stir-fry",
"time" : "10",
"name" : "edit name test",
"time" : "100",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "15.0g, scallion", "550.0g, tomatoes" ],
Expand Down
30 changes: 1 addition & 29 deletions data/plannedbook.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
{
"plannedRecipes" : [ {
"recipe" : {
"name" : "Barley Pilaf",
"time" : "50",
"isFavourite" : true,
"grains" : [ "0.5cup, small pieces of broken spaghetti" ],
"vegetables" : [ "2.0tbsp, chives (chopped)", "50.0g, small onion (chopped)" ],
"proteins" : [ "2.5cup, low-sodium chicken broth" ],
"fruits" : [ ],
"others" : [ "1.0cup, hulled barley", "10.0g, Salt & Pepper", "1.0tbsp, unsalted butter" ],
"steps" : [ "Melt butter in saucepan over medium heat. Add onion and cook until soft and light golden brown.", "Add barley and stir until grains are coated in butter.", "Add broth and 0.5 tsp salt, bring to a boil.", "Reduce heat to medium low, cover, and simmer for 20mins.", "Uncover and quickly stir in spaghetti. Cover and continue to simmer, stirring occasionally.", "Once most liquid is absorbed and barley and spaghetti are tender, remove from hit and let sit.", "Season to taste with salt and pepper and sprinkle with chopped chives." ],
"goals" : [ "Wholesome Wholemeal" ]
},
"date" : "2020-02-02"
}, {
"recipe" : {
"name" : "Asian BBQ Chicken",
"time" : "15",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "1.0tbsp, garlic & ginger (finely chopped)" ],
"proteins" : [ "100.0g, chicken breast" ],
"fruits" : [ ],
"others" : [ "2.0tbsp, char siew sauce", "1.0tsp, honey", "1.0tsp, rice vinegar", "1.0tsp, Salt & pepper", "0.5tsp, sesame oil" ],
"steps" : [ "In a bowl, mix all the ingredients to create marinade. Mix the chicken with the marinade.", "Pan sear the chicken from both sides.", "Serve with rice." ],
"goals" : [ "Bulk like the Hulk" ]
},
"date" : "2020-03-03"
} ]
"plannedRecipes" : [ ]
}
35 changes: 18 additions & 17 deletions src/main/java/seedu/recipe/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyPlannedBook> plannedBookOptional;
ReadOnlyPlannedBook initialPlannedData;

try {
plannedBookOptional = storage.readPlannedBook();
if (!plannedBookOptional.isPresent()) {
logger.info("Data file for planned recipes not found. Will be starting with a blank PlannedBook");
}
initialPlannedData = plannedBookOptional.orElse(new PlannedBook());

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty PlannedBook");
initialPlannedData = new PlannedBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty PlannedBook");
initialPlannedData = new PlannedBook();
}

try {
recipeBookOptional = storage.readRecipeBook();
if (!recipeBookOptional.isPresent()) {
Expand All @@ -100,8 +115,10 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
initialData = recipeBookOptional.orElseGet(SampleDataUtil::getSampleRecipeBook);

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty RecipeBook");
logger.warning("Data file not in the correct format. Will be starting with an empty RecipeBook"
+ " and PlannedBook");
initialData = new RecipeBook();
initialPlannedData = new PlannedBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file for recipes. "
+ "Will be starting with an empty RecipeBook");
Expand All @@ -123,22 +140,6 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
initialRecords = new CookedRecordBook();
}

try {
plannedBookOptional = storage.readPlannedBook();
if (!plannedBookOptional.isPresent()) {
logger.info("Data file for planned recipes not found. Will be starting with a blank PlannedBook");
}
initialPlannedData = plannedBookOptional.orElse(new PlannedBook());

} catch (DataConversionException e) {
// todo: split data conversion exception into diff types to handle this all in one try block
logger.warning("Data file not in the correct format. Will be starting with an empty PlannedBook");
initialPlannedData = new PlannedBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty PlannedBook");
initialPlannedData = new PlannedBook();
}

return new ModelManager(initialData, userPrefs, initialRecords, initialPlannedData);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/recipe/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_RECIPE_DISPLAYED_INDEX = "The recipe index provided is invalid";
public static final String MESSAGE_INVALID_PLANNED_DATE = "The date provided is invalid";
public static final String MESSAGE_INVALID_PLANNED_RECIPE_DISPLAYED_INDEX =
"The planned recipe index provided is invalid";
public static final String MESSAGE_RECIPES_LISTED_OVERVIEW = "%1$d recipes listed!";

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_OTHER;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_PROTEIN;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_VEGE;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.List;
Expand Down Expand Up @@ -78,6 +79,8 @@ public CommandResult execute(Model model) throws CommandException {
Recipe editedRecipe = createEditedRecipe(recipeToEdit, editRecipeDescriptor);
model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();

return new CommandResult(String.format(MESSAGE_ADD_INGREDIENTS_SUCCESS, recipeToEdit.getName().toString()));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/recipe/logic/commands/AddStepCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.recipe.logic.commands.EditCommand.createEditedRecipe;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_STEP;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.ArrayList;
Expand Down Expand Up @@ -62,6 +63,8 @@ public CommandResult execute(Model model) throws CommandException {
Recipe editedRecipe = createEditedRecipe(recipeToEdit, editRecipeDescriptor);
model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();

return new CommandResult(String.format(MESSAGE_ADD_STEPS_SUCCESS, recipeToEdit.getName().toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CommandResult execute(Model model) throws CommandException {
Index indexAfterEachDeletion = Index.fromZeroBased(targetIndex[i].getZeroBased() - i);
Recipe recipeToDelete = lastShownList.get(indexAfterEachDeletion.getZeroBased());
model.deleteRecipe(recipeToDelete);
model.removeAllPlannedMappingForRecipe(recipeToDelete);
model.deleteAllPlansFor(recipeToDelete);
if (i == targetIndex.length - 1 && targetIndex.length != 1) {
sb.append(" and ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_OTHER;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_PROTEIN;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_VEGE;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.List;
Expand Down Expand Up @@ -101,6 +102,8 @@ public CommandResult execute(Model model) throws CommandException {
Recipe editedRecipe = createEditedRecipe(recipeToEdit, editRecipeDescriptor);
model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();

return new CommandResult(String.format(MESSAGE_ADD_INGREDIENTS_SUCCESS, recipeToEdit.getName().toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.recipe.logic.commands.EditCommand.createEditedRecipe;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.ArrayList;
Expand Down Expand Up @@ -67,6 +68,8 @@ public CommandResult execute(Model model) throws CommandException {
Recipe editedRecipe = createEditedRecipe(recipeToEdit, editRecipeDescriptor);
model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();

return new CommandResult(String.format(MESSAGE_ADD_STEPS_SUCCESS, recipeToEdit.getName().toString()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/recipe/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setPlannedRecipe(recipeToEdit, editedRecipe);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();
return new CommandResult(String.format(MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_OTHER;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_PROTEIN;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_VEGE;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.List;
Expand Down Expand Up @@ -81,6 +82,8 @@ public CommandResult execute(Model model) throws CommandException {
Recipe editedRecipe = createEditedRecipe(recipeToEdit, editRecipeDescriptor);
model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();

return new CommandResult(String.format(MESSAGE_ADD_INGREDIENTS_SUCCESS, recipeToEdit.getName().toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.recipe.logic.commands.EditCommand.createEditedRecipe;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_STEP;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.ArrayList;
Expand Down Expand Up @@ -69,6 +70,8 @@ public CommandResult execute(Model model) throws CommandException {
Recipe editedRecipe = createEditedRecipe(recipeToEdit, editRecipeDescriptor);
model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();

return new CommandResult(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.recipe.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.Arrays;
Expand Down Expand Up @@ -52,6 +53,7 @@ public CommandResult execute(Model model) throws CommandException {
}
sb.append(" to favourites!");
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();
return new CommandResult(sb.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/recipe/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FindCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all recipes whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";
+ "Example: " + COMMAND_WORD + " Thai beef bowl";

private final NameContainsKeywordsPredicate predicate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.recipe.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES;

import java.util.Arrays;
Expand Down Expand Up @@ -52,6 +53,7 @@ public CommandResult execute(Model model) throws CommandException {
}
sb.append(" from favourites!");
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();
return new CommandResult(sb.toString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.recipe.logic.commands.plan;

import static java.util.Objects.requireNonNull;

import seedu.recipe.logic.commands.Command;
import seedu.recipe.logic.commands.CommandResult;
import seedu.recipe.model.Model;
import seedu.recipe.model.plan.PlannedBook;
import seedu.recipe.ui.tab.Tab;

/**
* Deletes all planned recipes.
*/
public class ClearPlanCommand extends Command {
public static final String COMMAND_WORD = "clearplan";
public static final String MESSAGE_SUCCESS = "Planned recipes have been cleared!";
private final Tab planTab = Tab.PLANNING;

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.setPlannedBook(new PlannedBook());
model.commitRecipeBook();
return new CommandResult(MESSAGE_SUCCESS, false, planTab, false);
}
}
Loading

0 comments on commit 32ab8e9

Please sign in to comment.