Skip to content

Commit

Permalink
Merge pull request #129 from beatricetay/branch-fix
Browse files Browse the repository at this point in the history
Fixed bugs where planned recipes do not get updated.
  • Loading branch information
YuuTon9 authored Apr 2, 2020
2 parents 6e047f6 + 99869e6 commit 3088c04
Show file tree
Hide file tree
Showing 46 changed files with 665 additions and 425 deletions.
41 changes: 33 additions & 8 deletions data/plannedbook.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
{
"plannedRecipes" : [ {
"recipes" : [ {
"name" : "Asian BBQ Chicken",
"name" : "testest",
"time" : "15",
"isFavourite" : true,
"grains" : [ "50.0g, grain", "30.0g, rice" ],
"vegetables" : [ ],
"proteins" : [ ],
"fruits" : [ "50.0g, fruit" ],
"others" : [ ],
"steps" : [ "step 1", "edited step 2" ],
"goals" : [ ]
}, {
"name" : "Quick Carrot Daikon Stir-fry",
"time" : "25",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "1.0tbsp, garlic & ginger (finely chopped)" ],
"proteins" : [ "100.0g, chicken breast" ],
"grains" : [ "30.0g, grain" ],
"vegetables" : [ "30.0g, carrot (julienned)", "500.0g, Daikon radish (peeled and julienned)", "30.0g, garlic clove (smashed and chopped)", "20.0g, ginger (julienned sliced)", "30.0g, scallions" ],
"proteins" : [ ],
"fruits" : [ ],
"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" ]
"others" : [ "50.0g, other", "50.0g, others", "1.5tbsp, oyster sauce", "0.5tsp, salt", "0.5tsp, sesame oil", "1.0tbsp, shaoxing wine", "3.0tbsp, vegetable oil", "0.25cup, water", "0.25tsp, white pepper" ],
"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" ]
} ],
"date" : "2020-05-02"
"date" : "2020-04-03"
}, {
"recipes" : [ {
"name" : "testest",
"time" : "15",
"isFavourite" : true,
"grains" : [ "50.0g, grain", "30.0g, rice" ],
"vegetables" : [ ],
"proteins" : [ ],
"fruits" : [ "50.0g, fruit" ],
"others" : [ ],
"steps" : [ "step 1", "edited step 2" ],
"goals" : [ ]
} ],
"date" : "2020-04-04"
} ]
}
39 changes: 14 additions & 25 deletions data/recipebook.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
{
"recipes" : [ {
"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", "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",
"time" : "20",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "1.0cup, bell peppers", "1.0cup, carrots (diced)", "1.0cup, chinese cabbage (diced)", "10.0g, garlic cloves", "10.0g, ginger", "1.0cup, onions (diced)" ],
"proteins" : [ "300.0g, chicken", "50.0g, egg" ],
"fruits" : [ "1.0cup, pineapple (diced)", "1.0tbsp, tomato juice" ],
"others" : [ "10.0g, Coriander (optional)", "1.5tsp, corn flour", "1.0tsp, light soya sauce", "1.0tbsp, vegetable oil" ],
"steps" : [ "Pound garlic and ginger into a paste. Marinade chicken in the paste, along with corn flour, soy sauce, and salt.", "In a wok, take some oil, saute the carrots, cabbage, onions, and bell peppers. Add tomato juice and bring to a slight boil.", "Fry the chicken and add to the wok along with some stock and set to simmer.", "Garnish with coriander and serve with rice." ],
"goals" : [ "Bulk like the Hulk" ]
}, {
"name" : "Quick Carrot Daikon Stir-fry",
"time" : "25",
"isFavourite" : false,
"grains" : [ ],
"vegetables" : [ "60.0g, carrot (julienned)", "500.0g, Daikon radish (peeled and julienned)", "30.0g, garlic clove (smashed and chopped)", "20.0g, ginger (julienned sliced)", "30.0g, scallions" ],
"grains" : [ "30.0g, grain" ],
"vegetables" : [ "30.0g, carrot (julienned)", "500.0g, Daikon radish (peeled and julienned)", "30.0g, garlic clove (smashed and chopped)", "20.0g, ginger (julienned sliced)", "30.0g, scallions" ],
"proteins" : [ ],
"fruits" : [ ],
"others" : [ "1.5tbsp, oyster sauce", "0.5tsp, salt", "0.5tsp, sesame oil", "1.0tbsp, shaoxing wine", "3.0tbsp, vegetable oil", "0.25cup, water", "0.25tsp, white pepper" ],
"others" : [ "50.0g, other", "50.0g, others", "1.5tbsp, oyster sauce", "0.5tsp, salt", "0.5tsp, sesame oil", "1.0tbsp, shaoxing wine", "3.0tbsp, vegetable oil", "0.25cup, water", "0.25tsp, white pepper" ],
"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" ]
}, {
Expand Down Expand Up @@ -142,5 +120,16 @@
"others" : [ ],
"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" ]
}, {
"name" : "testest",
"time" : "15",
"isFavourite" : true,
"grains" : [ "50.0g, grain", "30.0g, rice" ],
"vegetables" : [ ],
"proteins" : [ ],
"fruits" : [ "50.0g, fruit" ],
"others" : [ ],
"steps" : [ "step 1", "edited step 2" ],
"goals" : [ ]
} ]
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/recipe/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import seedu.recipe.model.Model;
import seedu.recipe.model.ModelManager;
import seedu.recipe.model.ReadOnlyCookedRecordBook;
import seedu.recipe.model.ReadOnlyPlannedBook;
import seedu.recipe.model.ReadOnlyRecipeBook;
import seedu.recipe.model.ReadOnlyUserPrefs;
import seedu.recipe.model.RecipeBook;
import seedu.recipe.model.UserPrefs;
import seedu.recipe.model.cooked.CookedRecordBook;
import seedu.recipe.model.plan.PlannedBook;
import seedu.recipe.model.plan.ReadOnlyPlannedBook;
import seedu.recipe.model.util.SampleDataUtil;
import seedu.recipe.storage.CookedRecordBookStorage;
import seedu.recipe.storage.JsonCookedRecordBookStorage;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/recipe/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.ReadOnlyRecipeBook;
import seedu.recipe.model.cooked.Record;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.recipe.Recipe;

/**
Expand Down Expand Up @@ -59,6 +59,6 @@ public interface Logic {
/**
* Returns an unmodifiable view of the scheduled recipes.
*/
ObservableList<PlannedRecipe> getFilteredPlannedList();
ObservableList<PlannedDate> getFilteredPlannedList();

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/recipe/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import seedu.recipe.model.Model;
import seedu.recipe.model.ReadOnlyRecipeBook;
import seedu.recipe.model.cooked.Record;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.recipe.Recipe;
import seedu.recipe.storage.Storage;

Expand Down Expand Up @@ -86,7 +86,7 @@ public ObservableList<Record> getFilteredRecordList() {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ 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.commitBook(commandType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ 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.commitBook(commandType);

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/recipe/logic/commands/CookedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public class CookedCommand extends Command {

private final Index[] targetIndex;
private final Tab goalsTab = Tab.GOALS;
private final CommandType commandType;

public CookedCommand(Index[] targetIndex) {
this.targetIndex = targetIndex;
this.commandType = CommandType.GOALS;
}

@Override
Expand Down Expand Up @@ -59,7 +61,7 @@ public CommandResult execute(Model model) throws CommandException {
}
}
sb.append("!");
model.commitRecipeBook();
model.commitBook(commandType);
return new CommandResult(sb.toString(), false, goalsTab, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ 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.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 @@ -94,7 +94,6 @@ 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.commitBook(commandType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ 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.commitBook(commandType);

Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/recipe/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public CommandResult execute(Model model) throws CommandException {

model.setRecipe(recipeToEdit, editedRecipe);
model.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES);
model.setRecipeInPlans(recipeToEdit, editedRecipe);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitBook(commandType);
return new CommandResult(String.format(MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ 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.commitBook(commandType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ 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.commitBook(commandType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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.commitBook(commandType);
return new CommandResult(sb.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import seedu.recipe.logic.commands.exceptions.CommandException;
import seedu.recipe.model.Date;
import seedu.recipe.model.Model;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.plan.PlannedRecipeOnDatePredicate;
import seedu.recipe.model.recipe.Recipe;
import seedu.recipe.ui.tab.Tab;
Expand Down Expand Up @@ -56,20 +56,20 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.updateFilteredPlannedList(new PlannedRecipeOnDatePredicate(atDate));
List<PlannedRecipe> plannedListAtDate = model.getFilteredPlannedList();
List<PlannedDate> plannedListAtDate = model.getFilteredPlannedList();

if (plannedListAtDate.size() != 1) {
throw new CommandException(Messages.MESSAGE_INVALID_PLANNED_DATE);
}

PlannedRecipe plannedRecipeToEdit = plannedListAtDate.get(0);
List<Recipe> recipesAtPlannedDate = plannedRecipeToEdit.getRecipes();
PlannedDate plannedDateToEdit = plannedListAtDate.get(0);
List<Recipe> recipesAtPlannedDate = plannedDateToEdit.getRecipes();
if (plannedIndex.getOneBased() > recipesAtPlannedDate.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PLANNED_RECIPE_DISPLAYED_INDEX);
}

Recipe recipeToDelete = recipesAtPlannedDate.get(plannedIndex.getZeroBased());
model.deleteRecipeFromOnePlan(recipeToDelete, plannedRecipeToEdit);
model.deleteOnePlan(recipeToDelete, plannedDateToEdit);
model.updateFilteredPlannedList(PREDICATE_SHOW_ALL_PLANNED_RECIPES);
model.commitBook(commandType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import seedu.recipe.model.Date;
import seedu.recipe.model.Model;
import seedu.recipe.model.plan.DuplicatePlannedRecipeException;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.recipe.Recipe;
import seedu.recipe.ui.tab.Tab;

Expand Down Expand Up @@ -69,10 +69,10 @@ public CommandResult execute(Model model) throws CommandException {
List<Recipe> recipesToPlan = new ArrayList<>();
recipesToPlan.add(recipeToPlan);

PlannedRecipe plannedRecipe = new PlannedRecipe(recipesToPlan, atDate);
PlannedDate plannedDate = new PlannedDate(recipesToPlan, atDate);

try {
model.addPlanForOneRecipe(recipeToPlan, plannedRecipe);
model.addOnePlan(recipeToPlan, plannedDate);
} catch (DuplicatePlannedRecipeException dp) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_PLANNED_RECIPE, atDate.toString(),
index.getOneBased()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PlanCommand parse(String args) throws ParseException {
}

Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
if (!date.isFutureDate()) {
if (!date.isDateInFuture()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, PlanCommand.MESSAGE_INVALID_DATE));
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/recipe/model/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Date() {
* Returns true if a given string is a valid date
*/
public static boolean isValidDate(String test) {
if (!test.matches(VALIDATION_REGEX)) {
if (test.isBlank() || !test.matches(VALIDATION_REGEX)) {
return false;
}
try {
Expand All @@ -75,7 +75,7 @@ public static Date today() {
/**
* Returns true if the date is older than today's date, according to the input timezone.
*/
public boolean isFutureDate() {
public boolean isDateInFuture() {
Date yesterday = new Date(LocalDate.now(ZONE_ID).minusDays(1));
return isAfter(yesterday);
}
Expand All @@ -85,7 +85,10 @@ public boolean isFutureDate() {
* The start and end dates are non-inclusive.
*/
public boolean isWithinRange(Date start, Date end) {
return date.isAfter(start.date) && date.isBefore(end.date);
if (!start.isAfter(end)) {
return date.isAfter(start.date) && date.isBefore(end.date);
}
return false;
}

/**
Expand Down
Loading

0 comments on commit 3088c04

Please sign in to comment.