Skip to content

Commit

Permalink
Bug fixes (#100)
Browse files Browse the repository at this point in the history
v2.1
  • Loading branch information
Remy9926 authored Nov 14, 2023
1 parent 8ef7eee commit 18756cd
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 959 deletions.
36 changes: 2 additions & 34 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package seedu.duke;

import java.util.ArrayList;

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.commands.ExitCommand;
import seedu.duke.commands.meal.MealCommand;
import seedu.duke.data.GoalList;
import seedu.duke.data.meal.Meal;
import seedu.duke.exerciselog.Exercise;
import seedu.duke.parser.Parser;
import seedu.duke.exerciselog.Log;
import seedu.duke.storagefile.AchmStorage;
import seedu.duke.storagefile.DataManager;
import seedu.duke.storagefile.GoalStorage;
import seedu.duke.ui.TextUi;
import seedu.duke.storagefile.ExerciseLogStorage;

Expand All @@ -27,13 +18,8 @@ public class Duke {
* Version info of the program.
*/
public static final String VERSION = "Version-2.1";
public static GoalList goals = new GoalList();
public static GoalList achievedGoals = new GoalList();
public static Log exerciseLog = new Log();
public static ExerciseLogStorage exerciseLogStorage;
public static GoalStorage goalStorage;
public static AchmStorage achmStorage;
private static ArrayList<Meal> meals = new ArrayList<Meal>();
public static TextUi ui;
private final String dirPath = "data";
private final String exerciseLogFilePath = "./data/ExerciseLog.txt";
Expand Down Expand Up @@ -63,21 +49,10 @@ public void run(String[] launchArgs) {
*/
private void start(String[] launchArgs) {
try {
this.ui = new TextUi();
exerciseLogStorage = StorageFile.initializeStorage(dirPath, exerciseLogFilePath);
ui = new TextUi();
exerciseLogStorage = ExerciseLogStorage.initializeStorage(dirPath, exerciseLogFilePath);
exerciseLogStorage.checkForLogTextFile(exerciseLog);
goalStorage = GoalStorage.initializeGoalStorage(dirPath, goalFilePath);
goalStorage.restoreGoalRecord();
achmStorage = AchmStorage.initializeGoalStorage(dirPath, achmFilePath);
achmStorage.restoreGoalRecord();
ui.showWelcomeMessage(VERSION, "storage.getPath()");
DataManager.setRelativePath(mealSavePath);
String dataJson = DataManager.readData();
ArrayList<Meal> data = DataManager.convertFromJsonToMealList(dataJson);
if (data != null) {
meals = data;
}
MealCommand.setMeals(meals);
} catch (Exception e) { // TODO: change to specific storage exceptions later
ui.showInitFailedMessage();
throw new RuntimeException(e);
Expand All @@ -89,11 +64,6 @@ private void start(String[] launchArgs) {
*/
private void exit() {
ui.showGoodbyeMessage();
try {
DataManager.saveData(DataManager.convertToJson(meals));
} catch (Exception exception) {
ui.showToUser(exception.toString());
}
System.exit(0);
}

Expand Down Expand Up @@ -131,10 +101,8 @@ private void runCommandLoopUntilExitCommand() {
private CommandResult executeCommand(Command command) {
try {
CommandResult result = command.execute();
// storage.save(addressBook);
return result;
} catch (Exception e) {
ui.showToUser(e.getMessage());
throw new RuntimeException(e);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/seedu/duke/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import seedu.duke.commands.goal.AchieveGoalCommand;
import seedu.duke.commands.goal.AchievementCommand;
import seedu.duke.commands.goal.GoalCommand;
import seedu.duke.commands.goal.ViewGoalCommand;
import seedu.duke.commands.logcommands.LogCommand;
import seedu.duke.commands.logcommands.ViewLogCommand;
Expand All @@ -21,15 +20,14 @@ public class HelpCommand extends Command {

@Override
public CommandResult execute() {
String HelpMsg = HelpCommand.MESSAGE_USAGE + "\n";
String helpMsg = HelpCommand.MESSAGE_USAGE + "\n";

return new CommandResult(
HelpMsg
helpMsg
+ "\n" + LogCommand.MESSAGE_USAGE
+ "\n" + DeleteLogCommand.MESSAGE_USAGE
+ "\n" + UpdateLogCommand.MESSAGE_USAGE
+ "\n" + ViewLogCommand.MESSAGE_USAGE
+ "\n" + GoalCommand.MESSAGE_USAGE
+ "\n" + DeleteLogCommand.MESSAGE_USAGE
+ "\n" + ViewGoalCommand.MESSAGE_USAGE
+ "\n" + AchieveGoalCommand.MESSAGE_USAGE
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package seedu.duke.commands.goal;

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;

import seedu.duke.data.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;

public class AchieveGoalCommand extends Command {
public static final String COMMAND_WORD = "achieve";
Expand All @@ -15,21 +11,4 @@ public class AchieveGoalCommand extends Command {
public AchieveGoalCommand(String cmd) {
super(cmd);
}

@Override
public CommandResult execute() {
try {
feedbackToUser = GoalList.achieveGoal(this.userCommand);

} catch (NumberFormatException nfe) {
feedbackToUser = "Please use a valid arabic number as index.";
} catch (IncorrectFormatException ife) {
feedbackToUser = ife.getMessage();
} catch (Exception e) {
feedbackToUser = "Something went wrong, please try again.";
}

return new CommandResult(feedbackToUser);
}

}
21 changes: 0 additions & 21 deletions src/main/java/seedu/duke/commands/goal/AchievementCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package seedu.duke.commands.goal;

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;
import seedu.duke.ui.TextUi;

public class AchievementCommand extends Command {
public static final String COMMAND_WORD = "achievement";
Expand All @@ -15,21 +11,4 @@ public class AchievementCommand extends Command {
public AchievementCommand(String cmd) {
super(cmd);
}

@Override
public CommandResult execute() {
try {
GoalList.verifyViewAchievementInput(this.userCommand);
feedbackToUser = TextUi.showAchievement();

} catch (IncorrectFormatException ife) {
feedbackToUser = ife.getMessage();
} catch (Exception e) {
feedbackToUser = "Something went wrong, please try again.";
}

return new CommandResult(feedbackToUser);
}


}
31 changes: 0 additions & 31 deletions src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package seedu.duke.commands.goal;

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;

import java.io.IOException;

public class DeleteGoalCommand extends Command {
public static final String COMMAND_WORD = "deleteg";
Expand All @@ -16,30 +11,4 @@ public class DeleteGoalCommand extends Command {
public DeleteGoalCommand(String cmd) {
super(cmd);
}

/**
* execute to remove a goal object from global goal list, by indexing
* If failed to delete a goal, tells user the specific problem.
* @return feedback to user of either success or fail
*/
@Override
public CommandResult execute() {
try {
feedbackToUser = GoalList.deleteGoal(this.userCommand);

} catch (NumberFormatException nfe) {
feedbackToUser = "Please input a valid number for delete index.";
} catch (IncorrectFormatException ife) {
feedbackToUser = ife.getMessage();
} catch (IOException io) {
feedbackToUser = "Failed to save data. Please check the output file and restart the app.";
} catch (Exception e) {
feedbackToUser = "Something went wrong, please try again.";
}


return new CommandResult(feedbackToUser);
}


}
50 changes: 0 additions & 50 deletions src/main/java/seedu/duke/commands/goal/GoalCommand.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package seedu.duke.commands.goal;

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;
import seedu.duke.ui.TextUi;

public class ViewGoalCommand extends Command {

Expand All @@ -16,19 +12,4 @@ public class ViewGoalCommand extends Command {
public ViewGoalCommand(String cmd) {
super(cmd);
}

@Override
public CommandResult execute() {
try {
GoalList.verifyViewGoalInput(this.userCommand);
feedbackToUser = TextUi.showGoalList();
} catch (IncorrectFormatException ife) {
feedbackToUser = ife.getMessage();
} catch (Exception e) {
feedbackToUser = "Something went wrong, please try again.";
}

return new CommandResult(feedbackToUser);
}

}
11 changes: 1 addition & 10 deletions src/main/java/seedu/duke/commands/meal/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package seedu.duke.commands.meal;

import seedu.duke.commands.CommandResult;
import seedu.duke.data.meal.Meal;
import seedu.duke.data.Date;

import java.util.List;
import java.util.Locale.Category;

public class AddCommand extends MealCommand {
public static final String COMMAND_WORD = "meal_add";
Expand All @@ -25,13 +22,7 @@ public AddCommand(List<String> arguments) throws Exception {
if (arguments.size() >= 4) {
time = new Date(arguments.get(3));
} else {
time = Date.Now();
time = Date.now();
}
}

@Override
public CommandResult execute() throws Exception {
meals.add(new Meal(name, calories, category, time));
return new CommandResult("Successfully add meal " + meals.get(meals.size() - 1) + "!");
}
}
13 changes: 0 additions & 13 deletions src/main/java/seedu/duke/commands/meal/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.duke.commands.meal;

import seedu.duke.commands.CommandResult;

import java.util.List;

public class DeleteCommand extends MealCommand {
Expand All @@ -18,15 +16,4 @@ public DeleteCommand(List<String> arguments) throws Exception {
throw new Exception("Invalid index!");
}
}

@Override
public CommandResult execute() throws Exception {
if (meals.size() <= index) {
return new CommandResult("Exceeded index!");
}
CommandResult result = new CommandResult(
"Successfully delete meal at index " + index + "!\n" + meals.get(index));
meals.remove(index);
return result;
}
}
Loading

0 comments on commit 18756cd

Please sign in to comment.