Skip to content

Commit

Permalink
Merge pull request #105 from beatricetay/planning-feature-list
Browse files Browse the repository at this point in the history
Planning Feature
  • Loading branch information
pekchinsiongbrian authored Mar 31, 2020
2 parents 655a944 + 3105067 commit 87eb853
Show file tree
Hide file tree
Showing 62 changed files with 1,493 additions and 227 deletions.
40 changes: 9 additions & 31 deletions data/addressbook.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
{
"recipes" : [ {
"name" : "Vegan Thai Green Curry Soup",
"time" : "35",
"isFavourite" : false,
"grains" : [ "200.0g, rice vermicelli noodles" ],
"vegetables" : [ "1.0cup, broccoli florets", "100.0g, button mushrooms sliced", "10.0g, Thai red eye bird's chili" ],
"proteins" : [ ],
"fruits" : [ ],
"others" : [ "0.5tsp, brown sugar", "0.25cup, coconut milk", "2.0tsp, oil", "1.0tsp, Salt", "1.0tsp, soy sauce", "1.0tbsp, Thai Green Curry Paste" ],
"steps" : [ "Heat oil in a saucepan. Add the vegetables (broccoli, mushroom) and saute till they turn soft. Transfer to a plate and set aside.", "In the same saucepan, add the green curry paste. Saute the curry paste for a minute.", "Add the coconut milk, brown sugar and soy sauce. Stir until the curry paste is nicely dissolved.", "Now add the vegetable stock, salt, red chillies and stir to combine.", "Bring the soup to a boil over high heat. Reduce the heat and allow the soup to simmer for 5 minutes.", "Add the vermicelli noodles and the vegetables. Simmer till the noodles are cooked.", "Turn off the heat and give soup a nice stir. Taste and adjust the seasoning and consistency accordingly. If too thick add more stock or coconut milk.", "Just before serving garnish soup with fresh herbs, crushed peanuts and juice of lemon.", "Serve Thai Green Curry Soup warm." ],
"goals" : [ "Herbivore" ]
}, {
"name" : "Thai Basil Ground Beef Bowl",
"time" : "25",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "2.0cup, asparagus (chopped)", "200.0g, cauliflower", "20.0g, garlic clove", "20.0g, garlic cloves (minced)", "0.25cup, onion", "0.25cup, Thai basil" ],
"proteins" : [ "500.0g, 95% lean ground beef", "1.0tbsp, fresh ginger (minced)" ],
"fruits" : [ ],
"others" : [ "2.0tsp, chilli paste", "1.0tbsp, coconut oil (or olive oil)", "2.0tbsp, low sodium soy sauce" ],
"steps" : [ "Prepare the cauliflower rice. Chop the cauliflower into florets and add to a food processor with the onion and garlic. Pulse into fine rice like pieces. You may have to do this in batches depending on your food processor. To cook, saute the cauliflower rice in 1 tbsp. coconut oil over medium heat until soft. You can also microwave it for 4-5 minutes.", "Add the beef to a hot nonstick skillet over medium high heat. Brown and break up the larger chunks as you go until no longer pink.", "Add in the garlic, ginger, green onions, and asparagus. Cook until the asparagus is just tender, about 3-4 minutes.", "Add the soy sauce, chili paste, and basil. Cook for 30 seconds and remove from heat. Taste and season as needed with additional soy or chili sauce.", "Serve the Thai Basil Beef over the cauliflower rice." ],
"goals" : [ "Bulk like the Hulk" ]
}, {
"name" : "Barley Pilaf",
"time" : "50",
"isFavourite" : false,
"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" ],
Expand All @@ -34,7 +12,7 @@
"goals" : [ "Wholesome Wholemeal" ]
}, {
"name" : "Asian BBQ Chicken",
"time" : "30",
"time" : "15",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "1.0tbsp, garlic & ginger (finely chopped)" ],
Expand Down Expand Up @@ -165,15 +143,15 @@
"steps" : [ "In a slow cooker, combine all ingredients and set to low heat. Cover and let cook for 8 to 9 hours.", "Stir and remove to serving bowls. This method works best if started before you go to bed." ],
"goals" : [ "Wholesome Wholemeal" ]
}, {
"name" : "testMissingIngredient",
"time" : "13",
"name" : "chicken rice",
"time" : "30",
"isFavourite" : false,
"grains" : [ ],
"grains" : [ "300.0g, Rice" ],
"vegetables" : [ ],
"proteins" : [ ],
"fruits" : [ "1.0cup, dried cranberries", "1.0cup, dried figs" ],
"proteins" : [ "300.0g, Chicken Thigh" ],
"fruits" : [ ],
"others" : [ ],
"steps" : [ ],
"goals" : [ ]
"steps" : [ "Boil chicken", "While chicken is cooking, add sesame oil and crushed ginger into rice and cook it", "When chicken is done, dip it into iced water", "Serve while rice is hot" ],
"goals" : [ "Bulk like the Hulk" ]
} ]
}
31 changes: 31 additions & 0 deletions data/plannedbook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"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"
} ]
}
30 changes: 27 additions & 3 deletions src/main/java/seedu/recipe/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
import seedu.recipe.model.ReadOnlyUserPrefs;
import seedu.recipe.model.RecipeBook;
import seedu.recipe.model.UserPrefs;
import seedu.recipe.model.plan.PlannedBook;
import seedu.recipe.model.plan.ReadOnlyPlannedBook;
import seedu.recipe.model.util.SampleDataUtil;
import seedu.recipe.storage.JsonRecipeBookStorage;
import seedu.recipe.storage.JsonUserPrefsStorage;
import seedu.recipe.storage.RecipeBookStorage;
import seedu.recipe.storage.Storage;
import seedu.recipe.storage.StorageManager;
import seedu.recipe.storage.UserPrefsStorage;
import seedu.recipe.storage.plan.JsonPlannedBookStorage;
import seedu.recipe.storage.plan.PlannedBookStorage;
import seedu.recipe.ui.Ui;
import seedu.recipe.ui.UiManager;

Expand Down Expand Up @@ -57,7 +61,8 @@ public void init() throws Exception {
UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefs userPrefs = initPrefs(userPrefsStorage);
RecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(userPrefs.getRecipeBookFilePath());
storage = new StorageManager(recipeBookStorage, userPrefsStorage);
PlannedBookStorage plannedBookStorage = new JsonPlannedBookStorage(userPrefs.getPlannedBookFilePath());
storage = new StorageManager(recipeBookStorage, plannedBookStorage, userPrefsStorage);

initLogging(config);

Expand All @@ -76,12 +81,15 @@ public void init() throws Exception {
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyRecipeBook> recipeBookOptional;
ReadOnlyRecipeBook initialData;
Optional<ReadOnlyPlannedBook> plannedBookOptional;
ReadOnlyPlannedBook initialPlannedData;
try {
recipeBookOptional = storage.readRecipeBook();
if (!recipeBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample RecipeBook");
logger.info("Data file for recipes not found. Will be starting with a sample RecipeBook");
}
initialData = recipeBookOptional.orElseGet(SampleDataUtil::getSampleRecipeBook);

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty RecipeBook");
initialData = new RecipeBook();
Expand All @@ -90,7 +98,23 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
initialData = new RecipeBook();
}

return new ModelManager(initialData, userPrefs);
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, initialPlannedData, userPrefs);
}

private void initLogging(Config config) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/recipe/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.recipe.logic.commands.exceptions.CommandException;
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.ReadOnlyRecipeBook;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.recipe.Recipe;

/**
Expand Down Expand Up @@ -47,4 +48,10 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

/**
* Returns an unmodifiable view of the scheduled recipes.
*/
ObservableList<PlannedRecipe> getFilteredPlannedList();

}
8 changes: 8 additions & 0 deletions src/main/java/seedu/recipe/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.Model;
import seedu.recipe.model.ReadOnlyRecipeBook;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.recipe.Recipe;
import seedu.recipe.storage.Storage;

Expand Down Expand Up @@ -43,6 +44,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
commandResult = command.execute(model);
try {
storage.saveRecipeBook(model.getRecipeBook());
storage.savePlannedBook(model.getPlannedBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
Expand Down Expand Up @@ -74,4 +76,10 @@ public GuiSettings getGuiSettings() {
public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}

@Override
public ObservableList<PlannedRecipe> getFilteredPlannedList() {
return model.getFilteredPlannedList();
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/recipe/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +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);
if (i == targetIndex.length - 1 && targetIndex.length != 1) {
sb.append(" and ");
}
Expand All @@ -52,6 +53,7 @@ public CommandResult execute(Model model) throws CommandException {
}
}
sb.append(" from recipe book!");

model.commitRecipeBook();
return new CommandResult(sb.toString());
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/recipe/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_STEP;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_TIME;
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 @@ -105,6 +106,8 @@ public CommandResult execute(Model model) throws CommandException {

model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setPlannedRecipe(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 @@ -2,23 +2,25 @@

import static java.util.Objects.requireNonNull;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_PLANNED_RECIPES;

import java.util.List;

import seedu.recipe.commons.core.Messages;
import seedu.recipe.commons.core.index.Index;
import seedu.recipe.logic.commands.exceptions.CommandException;
import seedu.recipe.model.Model;
import seedu.recipe.model.plan.Date;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.recipe.Recipe;

/**
* Schedules a recipe to a date.
*/

public class ScheduleCommand extends Command {
public class PlanCommand extends Command {

public static final String COMMAND_WORD = "schedule";
public static final String COMMAND_WORD = "plan";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Plans a recipe to be cooked on a certain date. "
+ "Parameters: "
Expand All @@ -31,12 +33,12 @@ public class ScheduleCommand extends Command {
public static final String MESSAGE_SUCCESS = "Recipe planned: %1$s, %2$s";

private final Index index;
private final Date atDate;
private final PlannedDate atDate;

/**
* Creates an ScheduleCommand to set the specified {@code Recipe} on a certain date
* Creates an PlanCommand to set the specified {@code Recipe} on a certain date
*/
public ScheduleCommand(Index index, Date date) {
public PlanCommand(Index index, PlannedDate date) {
requireNonNull(index);
requireNonNull(date);
this.index = index;
Expand All @@ -54,7 +56,11 @@ public CommandResult execute(Model model) throws CommandException {

Recipe recipeToPlan = lastShownList.get(index.getZeroBased());

model.planRecipe(recipeToPlan, atDate);
PlannedRecipe plannedRecipe = new PlannedRecipe(recipeToPlan, atDate);

model.addPlannedRecipe(plannedRecipe);
model.addPlannedMapping(recipeToPlan, plannedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitRecipeBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, recipeToPlan.toString(), atDate.toString()));
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/seedu/recipe/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package seedu.recipe.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.recipe.logic.commands.exceptions.CommandException;
import seedu.recipe.model.Model;
import seedu.recipe.model.plan.PlannedRecipeWithinDateRangePredicate;

/**
* Schedules a recipe to a date.
*/

public class ViewCommand extends Command {

public static final String COMMAND_WORD = "view";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Views the planned recipes in the specified format.";

public static final String MESSAGE_SUCCESS = "View format changed to %1$s";

private final PlannedRecipeWithinDateRangePredicate predicate;

private final String type = "week"; // change to enum types?

/**
* Creates an ViewCommand to set the view of the planned recipes.
*/
public ViewCommand(PlannedRecipeWithinDateRangePredicate predicate) {
requireNonNull(predicate);
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.updateFilteredPlannedList(predicate);
model.commitRecipeBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, type));
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.recipe.logic.parser;

import static java.util.Objects.requireNonNull;

import static seedu.recipe.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_GOAL;
import static seedu.recipe.logic.parser.CliSyntax.PREFIX_INGREDIENT_FRUIT;
Expand All @@ -20,13 +19,11 @@
import java.util.Set;

import seedu.recipe.commons.core.index.Index;

import seedu.recipe.logic.commands.EditCommand;
import seedu.recipe.logic.commands.EditCommand.EditRecipeDescriptor;
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.goal.Goal;
import seedu.recipe.model.recipe.Step;

import seedu.recipe.model.recipe.ingredient.Fruit;
import seedu.recipe.model.recipe.ingredient.Grain;
import seedu.recipe.model.recipe.ingredient.Other;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/recipe/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import seedu.recipe.commons.util.StringUtil;
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.goal.Goal;
import seedu.recipe.model.plan.Date;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.recipe.Name;
import seedu.recipe.model.recipe.Step;
import seedu.recipe.model.recipe.Time;
Expand Down Expand Up @@ -514,16 +514,16 @@ public static Set<Other> parseOthersNameOnly(Collection<String> others) throws P
}

/**
* Parses {@code String date} into a {@code Date}.
* Parses {@code String date} into a {@code PlannedDate}.
*
* @throws ParseException if the given {@code date} is invalid.
*/
public static Date parseDate(String date) throws ParseException {
public static PlannedDate parseDate(String date) throws ParseException {
requireNonNull(date);
String trimmedDate = date.trim();
if (!Date.isValidDate(trimmedDate)) {
throw new ParseException(Date.MESSAGE_CONSTRAINTS);
if (!PlannedDate.isValidDate(trimmedDate)) {
throw new ParseException(PlannedDate.MESSAGE_CONSTRAINTS);
}
return new Date(trimmedDate);
return new PlannedDate(trimmedDate);
}
}
Loading

0 comments on commit 87eb853

Please sign in to comment.