forked from nus-cs2103-AY2324S1/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 #63 from zekone/add-tag
Add tag-related features
- Loading branch information
Showing
19 changed files
with
760 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ If you can type fast, KeepInTouch can get your contact management tasks done fas | |
* [Adding a person: `add contact`](#adding-a-person--add-contact) | ||
* [Listing all persons: `list contact`](#listing-all-persons--list-contact) | ||
* [Deleting a person: `delete contact`](#deleting-a-person--delete-contact) | ||
* [Adding tags: `add tag`](#adding-tags--add-tag) | ||
* [Deleting tags: `delete tag`](#deleting-tags--delete-tag) | ||
* [Adding a note: `add note`](#adding-notes-to-a-contact--add-note) | ||
* [Listing all notes: `list notes`](#listing-all-notes--list-notes) | ||
* [Deleting a note: `delete note`](#deleting-a-note--delete-note) | ||
|
@@ -71,6 +73,9 @@ If you can type fast, KeepInTouch can get your contact management tasks done fas | |
|
||
* `CONTACT_ID` is the number that is on the left of the person's name in each person card. | ||
|
||
* Items with `…` after them can be used multiple times.<br> | ||
e.g. `[-t TAGNAME]…` can be used as `-t frontend`, `-t frontend -t java` etc. | ||
|
||
* Parameters can be in any order.<br> | ||
e.g. if the command specifies `-n NAME -t NOTE_TITLE`, `-t NOTE_TITLE -n NAME` is also acceptable. | ||
|
||
|
@@ -117,6 +122,39 @@ Format: `delete contact NAME` | |
Examples: | ||
* `list contact` followed by `delete contact Aaron` deletes the contact with the name Aaron. | ||
|
||
### Adding tags : `add tag` | ||
|
||
Adds one or more tags to a contact. | ||
|
||
Format: `add tag -id CONTACT_ID -t TAGNAME...` | ||
|
||
* Adds one or more tags to a contact. | ||
* Duplicates are accepted but only unique tags will be added. | ||
|
||
Requirements: | ||
* `TAGNAME` must be alphanumeric, with no spaces. | ||
|
||
Examples: | ||
* `add tag -id 1 -t frontend` adds a tag with tag name "frontend" to the first contact in the contact list. | ||
* `add tag -id 1 -t frontend -t java` adds two tags with tag name "frontend" and "java" to the first contact in the contact list. | ||
|
||
|
||
### Deleting tags : `delete tag` | ||
|
||
Deletes one or more tags to a contact. | ||
|
||
Format: `delete tag -id CONTACT_ID -t TAGNAME...` | ||
|
||
* Deletes one or more tags to a contact, regardless if the tag exists in the contact or not. | ||
* Duplicates are accepted but only unique tags will be added. | ||
|
||
Requirements: | ||
* `TAGNAME` must be alphanumeric, with no spaces. | ||
|
||
Examples: | ||
* `delete tag -id 1 -t frontend` deletes a tag with tag name "frontend" from the first contact in the contact list. | ||
* `add tag -id 1 -t frontend -t java` deletes two tags with tag name "frontend" and "java" from the first contact in the contact list. | ||
|
||
### Adding notes to a contact: `add note` | ||
|
||
Adds a note to a contact from the contact list. | ||
|
@@ -232,6 +270,8 @@ Action | Format, Examples | |
**Add Contact** | `add contact -n NAME -p PHONE_NUMBER -a ADDRESS -e EMAIL` <br> e.g., `add contact -n Aaron -p 12345678 -a Baker Street 12 -e [email protected]` | ||
**Delete Contact** | `delete contact NAME`<br> e.g., `delete contact Aaron` | ||
**List Contact** | `list contact` | ||
**Add Tag** | `add tag -id CONTACT_ID -t TAGNAME` <br> eg., `add tag -id 1 -t frontend` | ||
**Delete Tag** | `delete tag -id CONTACT_ID -t TAGNAME` <br> eg., `delete tag -id 1 -t frontend` | ||
**Add Note** | `add note -n NAME -t NOTE_TITLE -c NOTE_CONTENT` <br> e.g., `add note -n Daniel -t Open Position -e Applications for SWE full-time positions will open soon` | ||
**Delete Note** | `delete note -n NAME -t NOTE_TITLE`<br> e.g., `delete note -n Aaron -t Meeting Topics` | ||
**List Notes** | `list notes` | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
|
@@ -26,12 +27,14 @@ public class AddPersonCommand extends AddCommand { | |
+ PREFIX_NAME + " NAME " | ||
+ PREFIX_PHONE + " PHONE " | ||
+ PREFIX_EMAIL + " EMAIL " | ||
+ PREFIX_ADDRESS + " ADDRESS" + "\n" | ||
+ PREFIX_ADDRESS + " ADDRESS " | ||
+ PREFIX_TAG + " TAGNAME" + "\n" | ||
+ "Example: " + COMMAND_WORD + " " + SECONDARY_COMMAND_WORD | ||
+ PREFIX_NAME + " John Doe " | ||
+ PREFIX_PHONE + " 98765432 " | ||
+ PREFIX_EMAIL + " [email protected] " | ||
+ PREFIX_ADDRESS + " 311, Clementi Ave 2, #02-25 "; | ||
+ PREFIX_ADDRESS + " 311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_TAG + " frontend "; | ||
|
||
public static final String MESSAGE_SUCCESS = "New contact added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This contact already exists in the contact list"; | ||
|
79 changes: 79 additions & 0 deletions
79
src/main/java/seedu/address/logic/commands/AddTagCommand.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,79 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Set; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.ContactID; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* The command handler for {@code add tag} command | ||
*/ | ||
public class AddTagCommand extends AddCommand { | ||
public static final String SECONDARY_COMMAND_WORD = "tag"; | ||
public static final String MESSAGE_SUCCESS = "New tags added: "; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + " " + SECONDARY_COMMAND_WORD | ||
+ ": Adds tags to a contact from the contact list.\n" | ||
+ "Usage: add tag -id CONTACT_ID -t TAGNAME"; | ||
public static final String MESSAGE_PERSON_NOT_FOUND = "Can not find the target contact with ID: "; | ||
|
||
private final Set<Tag> toAdd; | ||
private final int contactId; | ||
|
||
/** | ||
* Creates an AddTagCommand to add the specified {@code Tag}(s). | ||
*/ | ||
public AddTagCommand(int contactId, Set<Tag> tagList) { | ||
requireNonNull(tagList); | ||
this.contactId = contactId; | ||
this.toAdd = tagList; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
Person person = model.findPersonByUserFriendlyId(ContactID.fromInt(this.contactId)); | ||
if (person == null) { | ||
throw new CommandException(MESSAGE_PERSON_NOT_FOUND + this.contactId); | ||
} | ||
person.addTags(this.toAdd); | ||
|
||
final StringBuilder builder = new StringBuilder(); | ||
builder.append(MESSAGE_SUCCESS); | ||
toAdd.forEach(builder::append); | ||
|
||
return new CommandResult(builder.toString()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddTagCommand)) { | ||
return false; | ||
} | ||
|
||
AddTagCommand otherAddNoteCommand = (AddTagCommand) other; | ||
|
||
boolean equalToAdd = toAdd.equals(otherAddNoteCommand.toAdd); | ||
boolean equalContactId = (contactId == otherAddNoteCommand.contactId); | ||
return equalToAdd && equalContactId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toAdd", toAdd) | ||
.add("contactId", contactId) | ||
.toString(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/seedu/address/logic/commands/DeleteTagCommand.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,78 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Set; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.ContactID; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* The command handler for {@code delete tag} command | ||
*/ | ||
public class DeleteTagCommand extends DeleteCommand { | ||
public static final String SECONDARY_COMMAND_WORD = "tag"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + " " | ||
+ SECONDARY_COMMAND_WORD + ": Delete one or more tags from a contact.\n" | ||
+ "Usage: delete tag -id CONTACT_ID -t TAGNAME"; | ||
public static final String MESSAGE_PERSON_NOT_FOUND = "Can not find the target contact with ID: "; | ||
public static final String MESSAGE_SUCCESS = "Successfully deleted tags: "; | ||
|
||
private final Set<Tag> toDelete; | ||
private final int contactId; | ||
|
||
/** | ||
* Creates an DeleteTagCommand to delete the specified {@code Tag}(s). | ||
*/ | ||
public DeleteTagCommand(int contactId, Set<Tag> tagList) { | ||
requireNonNull(tagList); | ||
this.contactId = contactId; | ||
this.toDelete = tagList; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
Person person = model.findPersonByUserFriendlyId(ContactID.fromInt(this.contactId)); | ||
if (person == null) { | ||
throw new CommandException(MESSAGE_PERSON_NOT_FOUND + this.contactId); | ||
} | ||
person.removeTags(toDelete); | ||
|
||
final StringBuilder builder = new StringBuilder(); | ||
builder.append(MESSAGE_SUCCESS); | ||
toDelete.forEach(builder::append); | ||
|
||
return new CommandResult(builder.toString()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteTagCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteTagCommand otherAddNoteCommand = (DeleteTagCommand) other; | ||
|
||
boolean equalToDelete = toDelete.equals(otherAddNoteCommand.toDelete); | ||
boolean equalContactId = (contactId == otherAddNoteCommand.contactId); | ||
return equalToDelete && equalContactId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toDelete", toDelete) | ||
.add("contactId", contactId) | ||
.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
41 changes: 41 additions & 0 deletions
41
src/main/java/seedu/address/logic/parser/AddTagCommandParser.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,41 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_INTEGER_ARGUMENT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PERSON_ID; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.Set; | ||
|
||
import seedu.address.logic.commands.AddTagCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddTagCommand object | ||
*/ | ||
public class AddTagCommandParser implements Parser<AddTagCommand> { | ||
@Override | ||
public AddTagCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PERSON_ID, | ||
PREFIX_TAG); | ||
|
||
if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_PERSON_ID, PREFIX_TAG) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTagCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_PERSON_ID); | ||
|
||
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
|
||
int contactId = -1; | ||
try { | ||
contactId = Integer.parseInt(argMultimap.getValue(PREFIX_PERSON_ID).get()); | ||
} catch (NumberFormatException e) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_INTEGER_ARGUMENT, e.getMessage())); | ||
} | ||
|
||
return new AddTagCommand(contactId, tagList); | ||
} | ||
} |
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.