diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index b41308a9b97..7b1f9429d4b 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -158,6 +158,23 @@ How the parsing works: - When called upon to parse a user command, the `AddressBookParser` class creates an `XYZCommandParser` (`XYZ` is a placeholder for the specific command name e.g., `AddCommandParser`) which uses the other classes shown above to parse the user command and create a `XYZCommand` object (e.g., `AddCommand`) which the `AddressBookParser` returns back as a `Command` object. - All `XYZCommandParser` classes (e.g., `AddCommandParser`, `DeleteCommandParser`, ...) inherit from the `Parser` interface so that they can be treated similarly where possible e.g, during testing. +#### Tasks + +Commands for tasks (e.g., `AddTaskCommand`, `MarkTaskCommand`, ...) follow a similar sequence of interactions within +the `Logic` component as the other commands described above. + +However, during execution, tasks commands may update the context of the current tasks of a team. To understand tasks better, +it should be understood that Tasks are an attribute of a Teams object, which is used to indicate if a tasks is done (also known as marked), +or not (also known as unmarked). + + +The Sequence Diagram below shows the interaction between `Logic` and `Model` components when `execute("at ..")` is called. + +[insert Sequence Diagram] + +This way of implementation of maintains abstraction of details of the `Logic` component, in the `Model` component. + + ### Model component **API** : [`Model.java`](https://github.com/AY2223S1-CS2103T-T11-1/tp/blob/master/src/main/java/seedu/address/model/Model.java) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 02fd256acba..8a11154a247 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -24,7 +24,7 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; - private final Index targetIndex; + final Index targetIndex; public DeleteCommand(Index targetIndex) { this.targetIndex = targetIndex; diff --git a/src/main/java/seedu/address/logic/commands/groups/GroupCommand.java b/src/main/java/seedu/address/logic/commands/groups/GroupCommand.java new file mode 100644 index 00000000000..5960a810863 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/groups/GroupCommand.java @@ -0,0 +1,47 @@ +package seedu.address.logic.commands.groups; + +import static java.util.Objects.requireNonNull; + +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.group.Group; + +/** + * Add a team to the address book. + */ +public class GroupCommand extends Command { + public static final String COMMAND_WORD = "team"; + + public static final String MESSAGE_SUCCESS = "New team added: %1$s!"; + public static final String MESSAGE_DUPLICATE_TEAM = "This team already exists in the address book"; + + private final Group toAdd; + /** + * Creates an AddCommand to add the specified {@code Person} + */ + public GroupCommand(Group team) { + requireNonNull(team); + toAdd = team; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + + if (model.hasTeam(toAdd)) { + throw new CommandException(MESSAGE_DUPLICATE_TEAM); + } + + model.addTeam(toAdd); + return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof GroupCommand // instanceof handles nulls + && toAdd.equals(((GroupCommand) other).toAdd)); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index b3a697f4052..8ba4bc6c33f 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -117,3 +117,4 @@ public Command parseCommand(String userInput) throws ParseException { } } + diff --git a/unused/DeleteGroupCommand.java b/unused/DeleteGroupCommand.java new file mode 100644 index 00000000000..5e2bf1d1e47 --- /dev/null +++ b/unused/DeleteGroupCommand.java @@ -0,0 +1,50 @@ +package seedu.address.logic.commands; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.group.Group; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +public class DeleteGroupCommand extends Command { + + public static final String COMMAND_WORD = "rmgroup"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Deletes the group identified by the index number used in the displayed group list.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_DELETE_GROUP_SUCCESS = "Deleted Group: %1$s"; + + private final Index targetIndex; + + public DeleteGroupCommand(Index targetIndex) { + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List<Group> lastShownList = model.getFilteredTeamList(); + + if (targetIndex.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Group groupToDelete = lastShownList.get(targetIndex.getZeroBased()); + model.deleteTeam(groupToDelete); + return new CommandResult(String.format(MESSAGE_DELETE_GROUP_SUCCESS, groupToDelete)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof DeleteCommand // instanceof handles nulls + && targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check + } +}