Skip to content

Commit

Permalink
Merge pull request #12 from liuziyang020319/master
Browse files Browse the repository at this point in the history
Fetch method
  • Loading branch information
LimHongYao authored Mar 15, 2023
2 parents 288dcbd + 9cb2a4c commit cd68a9f
Show file tree
Hide file tree
Showing 16 changed files with 311 additions and 86 deletions.
Empty file added data/recipeList.txt
Empty file.
5 changes: 3 additions & 2 deletions docs/team/liuziyang.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# John Doe - Project Portfolio Page
# Liu Ziyang - Project Portfolio Page

## Overview

Responsible for all items in the User Guide.

### Summary of Contributions

22 changes: 11 additions & 11 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.duke.parser.Parser;
import seedu.duke.recipe.RecipeList;
import seedu.duke.storage.Storage;
import seedu.duke.ui.Ui;
import seedu.duke.ui.UI;

/**
* Represents the Recipe Manager programme. A <code>Duke</code> object corresponds to
Expand All @@ -13,7 +13,7 @@
public class Duke {

private final RecipeList recipes;

private final UI ui = new UI();
/**
* Class constructor specifying filePath for saving data.
*
Expand All @@ -24,10 +24,10 @@ public Duke(String filePath) {
try {
Storage.createSavedFile();
} catch (Exception e) {
Ui.showLoadingErrorMessage(e);
ui.showLoadingErrorMessage(e);
} finally {
recipes = new RecipeList();
Ui.showLine();
ui.showLine();
}
}

Expand All @@ -36,20 +36,20 @@ public Duke(String filePath) {
* it is terminated by the user.
*/
public void run() {
Ui.showWelcome();
Ui.showLine();
ui.showWelcome();
ui.showLine();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = Ui.readCommand();
Ui.showLine();
String fullCommand = ui.readCommand();
ui.showLine();
Command c = Parser.parseCommands(fullCommand);
c.execute(recipes);
c.execute(recipes,ui);
isExit = c.isExit();
} catch (Exception e) {
Ui.showDudeMainError(e);
ui.showDudeMainError(e);
} finally {
Ui.showLine();
ui.showLine();
}
}
}
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/seedu/duke/DukeUI.java

This file was deleted.

42 changes: 29 additions & 13 deletions src/main/java/seedu/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import seedu.duke.recipe.IngredientList;
import seedu.duke.recipe.Recipe;
import seedu.duke.recipe.RecipeList;
import seedu.duke.ui.Ui;
import seedu.duke.ui.UI;

import java.util.ArrayList;

Expand Down Expand Up @@ -48,13 +48,13 @@ public boolean isExit() {
*
* @param recipeList the current list of recipes to be modified or used.
*/
public void execute(RecipeList recipeList) {
public void execute(RecipeList recipeList, UI ui) {

int recipeListIndex;

switch (type) {
case LIST:
Ui.showRecipeList(recipeList.getRecipeList());
ui.showRecipeList(recipeList.getRecipeList());
break;
case ADD:
try {
Expand All @@ -67,9 +67,9 @@ public void execute(RecipeList recipeList) {
String recipeTag = parsed.get(2);
ArrayList<String> recipeSteps = new ArrayList<>();
recipeList.addNewRecipe(new Recipe(recipeName, recipeTag, ingredientLists, recipeSteps));
Ui.showRecipeAdded(recipeList.getNewestRecipe(), recipeList.getCurrRecipeNumber());
ui.showRecipeAdded(recipeList.getNewestRecipe(), recipeList.getCurrRecipeNumber());
} catch (Exception e) {
Ui.showAddingRecipeErrorMessage(e);
ui.showAddingRecipeErrorMessage(e);
}
break;
case DELETE:
Expand All @@ -79,10 +79,10 @@ public void execute(RecipeList recipeList) {
}
recipeListIndex = Integer.parseInt(fullDescription);
Recipe recipeToBeDeleted = recipeList.getRecipeFromList(recipeListIndex);
Ui.showRecipeDeleted(recipeToBeDeleted, recipeList.getCurrRecipeNumber() - 1);
ui.showRecipeDeleted(recipeToBeDeleted, recipeList.getCurrRecipeNumber() - 1);
recipeList.removeRecipe(recipeListIndex);
} catch (Exception e) {
Ui.showDeletingTaskErrorMessage(e, type);
ui.showDeletingTaskErrorMessage(e, type);
}
break;
case FIND:
Expand All @@ -97,22 +97,38 @@ public void execute(RecipeList recipeList) {
findRecipeResults.add(recipe);
}
}
Ui.showFindResults(findRecipeResults, keywords);
ui.showFindResults(findRecipeResults, keywords);
} catch (Exception e) {
Ui.showFindingTaskErrorMessage(e);
ui.showFindingTaskErrorMessage(e);
}
break;
case CLEAR:
recipeList.clearRecipeList();
ui.showRecipeListCleared();
break;
case VIEW:
try {
if (fullDescription.isEmpty()) {
throw new IncompleteInputException("The index of " + type + " cannot be empty.\n");
}
recipeListIndex = Integer.parseInt(fullDescription);
Recipe recipeToBeViewed = recipeList.getRecipeFromList(recipeListIndex);
ui.showRecipeViewed(recipeToBeViewed);
} catch (Exception e) {
ui.showViewingRecipeErrorMessage(e);
}
break;
case HELP:
Ui.showHelp();
ui.showHelp();
break;
case EXIT:
Ui.showExit();
ui.showExit();
break;
case UNKNOWN:
Ui.showUnrecognizableErrorMessage();
ui.showUnrecognizableErrorMessage();
break;
default:
Ui.showUnrecognizableCommandErrorMessage();
ui.showUnrecognizableCommandErrorMessage();
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/seedu/duke/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public enum CommandType {
*/
HELP,
/**
* Terminates the programme and exit with saving.
* Clear the current recipe list.
*/
CLEAR,
/**
* Terminates the programme and exit without saving.
*/
EXIT,
/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public static Command parseCommands(String line) {
case "find":
type = CommandType.FIND;
break;
case "clear":
type = CommandType.CLEAR;
break;
case "exit":
type = CommandType.EXIT;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/duke/recipe/Ingredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ public class Ingredient {
public Ingredient(String inputName) {
name = inputName;
}
public String getName() {
return name;
}
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/duke/recipe/IngredientList.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ private void removeIngredient(int index) {
list.remove(index-1);
currIngredientNumber--;
}
public void showList() {
System.out.println("Here are " + currIngredientNumber + " ingredients in the list:");
for (int i = 0; i < currIngredientNumber; i++) {
System.out.println((i + 1) + ". " + list.get(i).getName());
}
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/duke/recipe/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public String getName() {
public String getTag() {
return tag;
}

public String toString() {
return '[' + tag + "] " + name;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/duke/recipe/RecipeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ArrayList<Recipe> getRecipeList() {
}

public int getCurrRecipeNumber() {
assert(currRecipeNumber == recipeList.size());
return currRecipeNumber;
}

Expand All @@ -46,4 +47,8 @@ public void removeRecipe(int index) throws RecipeListEmptyError {
recipeList.remove(index-1);
currRecipeNumber--;
}
public void clearRecipeList() {
recipeList.clear();
currRecipeNumber = 0;
}
}
6 changes: 4 additions & 2 deletions src/main/java/seedu/duke/ui/StringLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface StringLib {
+ " \\_/\\__,_|___/\\__\\___| \\___/|_| \\_| |_/\\___/|_| |_| |_| |___/ | | \\_/ \\___/\\_| |_/| |"
+ "\n"
+ " \\_\\ /_/\n";
String WELCOME_MESSAGE = "\nHELLLOO there! I am\n "
String WELCOME_MESSAGE = "\nHELLO there! I am\n "
+ LOGO + '\n'
+ "Your personal recipes assistant!\n"
+ "What can I do for you today?\n\n"
Expand Down Expand Up @@ -83,6 +83,8 @@ public interface StringLib {
+ "\nException occurred: ";
String RECIPE_FINDING_DEFAULT_ERROR = "\nError in finding recipe!"
+ "\nException occurred: ";
String RECIPE_VIEWING_DEFAULT_ERROR = "\nError in viewing recipe!"
+ "\nException occurred: ";
String FORMAT_CONVERT_ERROR = "\nError in inputs!"
+ "\nException occurred: The number is too big to process or the inputs contains words when "
+ "it is supposed to be numbers."
Expand All @@ -106,5 +108,5 @@ public interface StringLib {
+ "i/<insert ingredients with \\\", \\\" separation> \"\n"
+ "\"t/<insert cuisine>\\\"\\n\"\n"
+ "\"Example use : \\\"add n/Hotpot i/Beef, Potatoes, Carrots t/Chinese\\\" \\n \\n\"";

String RECIPE_CLEARED_MESSAGE = "\nAll recipes have been cleared!";
}
Loading

0 comments on commit cd68a9f

Please sign in to comment.