Skip to content

Commit

Permalink
Recover all goal command executions
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Y-Yan committed Nov 14, 2023
1 parent f911de5 commit 7e6e5c8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 @@ -11,4 +15,21 @@ 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: 21 additions & 0 deletions src/main/java/seedu/duke/commands/goal/AchievementCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 @@ -11,4 +15,21 @@ 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: 31 additions & 0 deletions src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
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 @@ -11,4 +16,30 @@ 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);
}


}
19 changes: 19 additions & 0 deletions src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 @@ -12,4 +16,19 @@ 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);
}

}

0 comments on commit 7e6e5c8

Please sign in to comment.