forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from DanzaSeah/branch-Task
Add support for creating, deleting and listing tasks
- Loading branch information
Showing
97 changed files
with
4,130 additions
and
56 deletions.
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
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
85 changes: 85 additions & 0 deletions
85
src/main/java/seedu/address/logic/commands/CreateTaskCommand.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,85 @@ | ||
package seedu.address.logic.commands; | ||
|
||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK; | ||
|
||
import java.util.HashSet; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Adds a Task to the address book. | ||
*/ | ||
public class CreateTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "create-task"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Creates a task in the address book. \n" | ||
+ "Parameters: " | ||
+ PREFIX_TASK + "TASK_TYPE TASK_DESCRIPTION [ADDITIONAL_FIELDS]\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_TASK + "todo Setup venue decorations\n" | ||
+ COMMAND_WORD + " " | ||
+ PREFIX_TASK + "deadline Submit proposal /by 2024-10-31"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New task added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the address book"; | ||
|
||
private final HashSet<Task> tasksToAdd; | ||
|
||
/** | ||
* Creates a CreateTaskCommand to add the specified {@code task} to the Wedlinker | ||
* @param task The {@code task} to be added to the Wedlinker | ||
*/ | ||
public CreateTaskCommand(HashSet<Task> task) { | ||
requireNonNull(task); | ||
tasksToAdd = task; | ||
} | ||
|
||
/** | ||
* Returns the set of tasks to be added. | ||
*/ | ||
public HashSet<Task> getTaskToAdd() { | ||
return tasksToAdd; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
for (Task task : tasksToAdd) { | ||
if (model.hasTask(task)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_TASK); | ||
} | ||
model.addTask(task); | ||
} | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, tasksToAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) { | ||
return true; | ||
} | ||
|
||
// null case handled by instanceof | ||
if (!(obj instanceof CreateTaskCommand)) { | ||
return false; | ||
} | ||
|
||
CreateTaskCommand otherCreateTaskCommand = (CreateTaskCommand) obj; | ||
return tasksToAdd.equals(otherCreateTaskCommand.tasksToAdd); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("taskToAdd", tasksToAdd) | ||
.toString(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/seedu/address/logic/commands/DeleteTaskCommand.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,69 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
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; | ||
|
||
/** | ||
* Deletes a task identified using it's displayed index from the address book. | ||
*/ | ||
public class DeleteTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "delete-task"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the task identified by the index number used in the displayed task list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted task: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteTaskCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Task> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
Task taskToDelete = lastShownList.get(targetIndex.getZeroBased()); | ||
model.deleteTask(taskToDelete); | ||
return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete.toString())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteTaskCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteTaskCommand otherDeleteTaskCommand = (DeleteTaskCommand) other; | ||
return targetIndex.equals(otherDeleteTaskCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", targetIndex) | ||
.toString(); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/seedu/address/logic/commands/ListTasksCommand.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,25 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS; | ||
|
||
import seedu.address.logic.commands.CommandResult.SwitchView; | ||
import seedu.address.model.Model; | ||
|
||
|
||
/** | ||
* Lists all tasks in the address book to the user. | ||
*/ | ||
public class ListTasksCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "list-tasks"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all tasks"; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS); | ||
return new CommandResult(MESSAGE_SUCCESS, SwitchView.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
Oops, something went wrong.