Skip to content

Commit

Permalink
Merge pull request #118 from DanzaSeah/branch-Task
Browse files Browse the repository at this point in the history
Add support for creating, deleting and listing tasks
  • Loading branch information
HanB1n authored Oct 24, 2024
2 parents 60d87ce + ca8d9a6 commit 247a5d3
Show file tree
Hide file tree
Showing 97 changed files with 4,130 additions and 56 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;
import seedu.address.model.wedding.Wedding;

/**
Expand All @@ -34,6 +35,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of tasks */
ObservableList<Task> getFilteredTaskList();

/** Returns an unmodifiable view of the filtered list of weddings */
ObservableList<Wedding> getFilteredWeddingList();

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;
import seedu.address.model.wedding.Wedding;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -72,6 +73,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Task> getFilteredTaskList() {
return model.getFilteredTaskList();
}

@Override
public ObservableList<Wedding> getFilteredWeddingList() {
return model.getFilteredWeddingList();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.parser.Prefix;
import seedu.address.model.person.Person;
import seedu.address.model.tag.Tag;
import seedu.address.model.task.Task;
import seedu.address.model.wedding.Wedding;

/**
Expand All @@ -18,6 +19,20 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided is invalid";
public static final String MESSAGE_INVALID_DATE_FORMAT = "Invalid date format. Expected format: yyyy-MM-dd";

public static final String MESSAGE_INVALID_TASK_TYPE = "Unknown task type: %1$s. "
+ "Expected one of: todo, deadline, event.";

public static final String MESSAGE_INVALID_DEADLINE_FORMAT = "Invalid deadline format. "
+ "Usage: create-task tk/deadline [description] /by [date]";
public static final String MESSAGE_INVALID_EVENT_FORMAT = "Invalid event format."
+ " Usage: create-task tk/event [description] /from [start] /to [end]";

public static final String MESSAGE_INCOMPLETE_TASK_DESCRIPTION = "Task description is incomplete. "
+ "Expected format: tk/[task type] [task details].";
public static final String MESSAGE_TO_BEFORE_FROM_INVALID = "\"From\" date must be before \"To\" date.";
public static final String MESSAGE_INVALID_WEDDING_DISPLAYED_INDEX = "The wedding index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
Expand Down Expand Up @@ -78,4 +93,7 @@ public static String format(Wedding wedding) {
return wedding.getWeddingName().toString();
}

public static String format(Task task) {
return task.getDescription();
}
}
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public class CommandResult {
private final boolean exit;

/**
* Which view to switch to.
* Enum to indicate which view to switch to.
*/
public enum SwitchView {
PERSON,
WEDDING,
TASK,
NONE
}

Expand Down Expand Up @@ -77,7 +78,7 @@ public boolean isShowHelp() {
*/
public boolean isSwitchView() {
return switch (switchView) {
case PERSON, WEDDING -> true;
case PERSON, WEDDING, TASK -> true;
default -> false;
};
}
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/seedu/address/logic/commands/CreateTaskCommand.java
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 src/main/java/seedu/address/logic/commands/DeleteTaskCommand.java
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();
}
}
24 changes: 23 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;
import seedu.address.model.task.Task;
import seedu.address.model.wedding.Wedding;

/**
Expand Down Expand Up @@ -104,8 +105,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Set<Wedding> updatedWeddings = editPersonDescriptor.getWeddings().orElse(personToEdit.getWeddings());
Set<Task> updatedTasks = editPersonDescriptor.getTasks().orElse(personToEdit.getTasks());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedWeddings);
return new Person(updatedName, updatedPhone, updatedEmail,
updatedAddress, updatedTags, updatedWeddings, updatedTasks);
}

@Override
Expand Down Expand Up @@ -143,6 +146,7 @@ public static class EditPersonDescriptor {
private Address address;
private Set<Tag> tags;
private Set<Wedding> weddings;
private Set<Task> tasks;

public EditPersonDescriptor() {}

Expand All @@ -157,6 +161,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setAddress(toCopy.address);
setTags(toCopy.tags);
setWeddings(toCopy.weddings);
setTasks(toCopy.tasks);
}

/**
Expand Down Expand Up @@ -206,6 +211,23 @@ public void setTags(Set<Tag> tags) {
this.tags = (tags != null) ? new HashSet<>(tags) : null;
}

/**
* Returns an unmodifiable task set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tasks} is null.
*/
public Optional<Set<Task>> getTasks() {
return (tasks != null) ? Optional.of(Collections.unmodifiableSet(tasks)) : Optional.empty();
}

/**
* Sets {@code tasks} to this object's {@code tasks}.
* A defensive copy of {@code tasks} is used internally.
*/
public void setTasks(Set<Task> tasks) {
this.tasks = (tasks != null) ? new HashSet<>(tasks) : null;
}

/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/logic/commands/ListTasksCommand.java
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);
}
}
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/TagCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit.getEmail(),
personToEdit.getAddress(),
updatedTags,
personToEdit.getWeddings());
personToEdit.getWeddings(),
personToEdit.getTasks());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/UntagCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit.getEmail(),
personToEdit.getAddress(),
updatedTags,
personToEdit.getWeddings());
personToEdit.getWeddings(),
personToEdit.getTasks());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit.getEmail(),
personToEdit.getAddress(),
personToEdit.getTags(),
updatedWeddings);
updatedWeddings,
personToEdit.getTasks());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit.getEmail(),
personToEdit.getAddress(),
personToEdit.getTags(),
updatedWeddings);
updatedWeddings,
personToEdit.getTasks());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
Expand Down
Loading

0 comments on commit 247a5d3

Please sign in to comment.