forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Undo command #147
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,8 +185,9 @@ Here is a reference table that briefly summarizes available commands: | |
| `list` | Displays all clients currently stored in the system. | | ||
| `filter` | Filters clients based on specified criteria | | ||
| `view` | Opens a split view showing detailed client information | | ||
| `close` | Closes the split view of client details | | ||
| `close` | Closes the split view of client details | | ||
| `clear` | Deletes all clients from the system. | | ||
| `undo` | Undoes latest command. | | ||
| `help` | Displays a list of available commands and their usage. | | ||
| `exit` | Exits the AgentAssist application. | | ||
|
||
|
@@ -726,8 +727,9 @@ Each credit card tier is visually distinguished in the UI: Gold is marked with a | |
| **Edit Existing Client** | `edit <INDEX> n/<NAME> p/<PHONE> e/<EMAIL> a/<ADDRESS> j/<JOB> i/<INCOME> [t/<TIER>] [rn/<NEW REMARK>] [ra/<APPEND REMARK>]` | `edit 69 n/ GORDON MOORE p/ 77337733 e/ [email protected] a/ COM3 j/ doctor i/ 1000000000 ra/ added info` | | ||
| **List All Clients** | `list` | `list` | | ||
| **Filter Client List** | `filter [n/<NAME>] [p/<PHONE>] [e/<EMAIL>] [a/<ADDRESS>] [j/<JOB>] [r/<REMARK>] [t/<TIER>] [i/<INCOME>]` | `filter n/ GORDON MOORE j/ doctor t/ gold` | | ||
| **View Client Details** | `view <INDEX>` | `view 1` | | ||
| **View Client Details** | `view <INDEX>` | `view 1` | | ||
| **Close Client Details** | `close` | `close` | | ||
| **View Help** | `help` | `help` | | ||
| **Undo Command** | `undo` | `undo` | | ||
| **Exit Application** | `exit` | `exit` | | ||
| **Clear All Data** | `clear` | `clear` | |
28 changes: 28 additions & 0 deletions
28
src/main/java/seedu/address/logic/commands/UndoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Undoes the latest command. Throws an error if there is no previous command/ if previous command does | ||
* not make changes to the Model. | ||
*/ | ||
public class UndoCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "undo"; | ||
public static final String MESSAGE_SUCCESS = "Your latest command has been undone."; | ||
public static final String MESSAGE_NO_COMMAND_TO_UNDO = "Please input a command first in order to undo it."; | ||
|
||
@Override | ||
protected CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
if (!model.hasPreviousCommand()) { | ||
throw new CommandException(MESSAGE_NO_COMMAND_TO_UNDO); | ||
} | ||
model.undoCommand(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/seedu/address/logic/commands/UndoCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAgentAssist; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.testutil.EditPersonDescriptorBuilder; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
public class UndoCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalAgentAssist(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_undo_success() { | ||
Person editedPerson = new PersonBuilder().build(); | ||
EditCommand.EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build(); | ||
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor); | ||
try { | ||
CommandResult result = editCommand.execute(model); | ||
} catch (CommandException ce) { | ||
throw new AssertionError("Execution of command should not fail.", ce); | ||
} | ||
|
||
UndoCommand undoCommand = new UndoCommand(); | ||
Model expectedModel = new ModelManager(getTypicalAgentAssist(), new UserPrefs()); | ||
|
||
assertCommandSuccess(undoCommand, model, UndoCommand.MESSAGE_SUCCESS, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_noPreviousCommand_failure() { | ||
Model model = new ModelManager(); | ||
assertCommandFailure(new UndoCommand(), model, UndoCommand.MESSAGE_NO_COMMAND_TO_UNDO); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of abstraction! Liked how clean this is with just adding saveHistory into each command works.