forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add personal tasks #34
Merged
Yskie
merged 13 commits into
AY2324S2-CS2103T-W13-4:master
from
Kaya3842:branch-add-tasks
Mar 15, 2024
+1,199
−42
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2caf627
Create Task class
Kaya3842 815607a
Create AddTaskCommand and AddTaskCommandParser classes
Kaya3842 1a40f52
Create TaskList class
Kaya3842 7dc4a27
Update add task logic
Kaya3842 78eade9
Create TaskList Storage classes
Kaya3842 449814c
Update Storage
Kaya3842 20ebd42
Update test files
Kaya3842 f9024e6
Add more test files
Kaya3842 cda4b66
Add more test files
Kaya3842 74c69c4
Add more tests
Kaya3842 cbed918
Update StorageManagerTest
Kaya3842 aa11001
Fix StorageManagerTest
Kaya3842 c809106
Add more test files
Kaya3842 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
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
72 changes: 72 additions & 0 deletions
72
src/main/java/seedu/address/logic/commands/AddTaskCommand.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,72 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Adds a task to the task list. | ||
*/ | ||
public class AddTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "addtask"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task list. " | ||
+ "Parameter: <description> the description of the task."; | ||
public static final String MESSAGE_SUCCESS = "New task added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task list."; | ||
|
||
private final Task toAdd; | ||
|
||
/** | ||
* Creates an AddTaskCommand to add the specified {@code Task} | ||
*/ | ||
public AddTaskCommand(Task task) { | ||
requireNonNull(task); | ||
toAdd = task; | ||
} | ||
|
||
/** | ||
* Executes the command and returns the result message. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return feedback message of the operation result for display | ||
* @throws CommandException If an error occurs during command execution. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasTask(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_TASK); | ||
} | ||
|
||
model.addTask(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.formatTask(toAdd))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddCommand)) { | ||
return false; | ||
} | ||
|
||
AddTaskCommand otherAddTaskCommand = (AddTaskCommand) other; | ||
return toAdd.equals(otherAddTaskCommand.toAdd); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toAdd", toAdd) | ||
.toString(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/parser/AddTaskCommandParser.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,30 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.logic.commands.AddTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddTaskCommand object | ||
*/ | ||
public class AddTaskCommandParser implements Parser<AddTaskCommand> { | ||
|
||
/** | ||
* Parses {@code userInput} into a command and returns it. | ||
* | ||
* @param userInput | ||
* @throws ParseException if {@code userInput} does not conform the expected format | ||
*/ | ||
@Override | ||
public AddTaskCommand parse(String userInput) throws ParseException { | ||
if (userInput.isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTaskCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Task task = new Task(userInput); | ||
return new AddTaskCommand(task); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,6 @@ public interface ReadOnlyUserPrefs { | |
|
||
Path getAddressBookFilePath(); | ||
|
||
Path getTaskListFilePath(); | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
nit-pick, might be better to just overload the
format(Person)
method and name thisformat
as well?