From 7e6e5c82b44c245c61c959635a3b2677a014476d Mon Sep 17 00:00:00 2001 From: "MSI\\jyben" Date: Tue, 14 Nov 2023 20:25:13 +0800 Subject: [PATCH] Recover all goal command executions --- .../commands/goal/AchieveGoalCommand.java | 21 +++++++++++++ .../commands/goal/AchievementCommand.java | 21 +++++++++++++ .../duke/commands/goal/DeleteGoalCommand.java | 31 +++++++++++++++++++ .../duke/commands/goal/ViewGoalCommand.java | 19 ++++++++++++ 4 files changed, 92 insertions(+) diff --git a/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java b/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java index d801a612dc..f08530b1dd 100644 --- a/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java @@ -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"; @@ -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); + } + } diff --git a/src/main/java/seedu/duke/commands/goal/AchievementCommand.java b/src/main/java/seedu/duke/commands/goal/AchievementCommand.java index 9b36bfb645..a35d60a779 100644 --- a/src/main/java/seedu/duke/commands/goal/AchievementCommand.java +++ b/src/main/java/seedu/duke/commands/goal/AchievementCommand.java @@ -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"; @@ -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); + } + + } diff --git a/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java b/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java index c552ad4a24..9e2c36cd48 100644 --- a/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java @@ -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"; @@ -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); + } + + } diff --git a/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java b/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java index 143e94f61a..d000aade58 100644 --- a/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java @@ -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 { @@ -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); + } + }