From 245cce524e8c52502e2ac71efbaee5dad802e086 Mon Sep 17 00:00:00 2001 From: Newton Koh Date: Tue, 12 Mar 2024 16:46:26 +0800 Subject: [PATCH 01/17] Add use cases for features --- docs/DeveloperGuide.md | 180 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 175 insertions(+), 5 deletions(-) diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index a1a0db64847..bca1f6dacbe 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -322,16 +322,186 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli (For all use cases below, the **System** is the `AddressBook` and the **Actor** is the `user`, unless specified otherwise) +___ + **Use case: Delete a person** +***Preconditions:*** User is logged into the system. + **MSS** -1. User requests to list persons -2. AddressBook shows a list of persons -3. User requests to delete a specific person in the list -4. AddressBook deletes the person +1. User requests to list persons +2. AddressBook shows a list of persons +3. User requests to delete a specific person in the list +4. AddressBook deletes the person + +***Postconditions:*** A contact is deleted from the address book. + +___ + +**Use Case: Add Contact** + +***Preconditions:*** User is logged into the system. + +**MSS** + +1. User selects the option to add a new contact. +2. User enters the contact's name, phone number, and any other optional information. +3. System validates the provided information. +4. System adds the new contact to the address book. +5. System displays a confirmation message. + +***Postconditions:*** A new contact is added to the address book. + +***Alternate Flows:*** If the information fails validation, the system notifies the user and requests correct data. + +___ + +**Use Case: Delete Contact** + +***Preconditions:*** User is logged into the system and the address book contains at least one contact. + +**MSS** + +1. User requests a list of contacts and selects one to delete. +2. System requests confirmation for deletion. +3. User confirms. +4. System deletes the selected contact from the address book. +5. System displays a confirmation message. + +***Postconditions:*** The selected contact is removed from the address book. + +***Alternate Flows:*** If the user cancels the deletion, no action is taken. + +___ + +**Use Case: Edit Contact** + +***Preconditions:*** User is logged into the system and the address book contains at least one contact. + +**MSS** + +1. User requests to edit a contact and selects one from the list. +2. System displays the selected contact’s current information. +3. User updates the necessary information. +4. System validates the updated information. +5. System updates the contact details in the address book. +6. System displays a confirmation message. + +***Postconditions:*** The selected contact's information is updated in the address book. + +***Alternate Flows:*** If the updated information fails validation, the system notifies the user and requests correct data. + +___ + +**Use Case: Store Phone Number** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides a phone number for the contact. +2. System validates the phone number format. +3. System stores the phone number with the contact’s information. + +***Postconditions:*** The contact's phone number is stored or updated. + +___ + +**Use Case: View Contacts** + +***Preconditions:*** User is logged into the system. + +**MSS** + +1. User selects the option to view contacts. +2. System retrieves and displays all contacts from the address book. + +***Postconditions:*** User views the list of all contacts in the address book. + +___ + +**Use Case: Store Address** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides an address for the contact. +2. System validates the address format. +3. System stores the address with the contact’s information. + +***Postconditions:*** The contact's address is stored or updated. + +___ + +**Use Case: Store Tags** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides one or more tags for the contact. +2. System stores the tags with the contact’s information. + +***Postconditions:*** The contact's tags are stored or updated. + +___ + +**Use Case: Store Email** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides an email address for the contact. +2. System validates the email format. +3. System stores the email with the contact’s information. + +***Postconditions:*** The contact's email address is stored or updated. + +___ + +**Use Case: Store Money Owed** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides an amount of money owed for the contact. +2. System validates the money format. +3. System stores the money owed information with the contact’s details. + +***Postconditions:*** The contact's money owed information is stored or updated. + +___ + +**Use Case: Store Birthday** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides a birthday for the contact. +2. System validates the birthday format. +3. System stores the birthday with the contact’s information. + +***Postconditions:*** The contact's birthday is stored or updated. + +___ + +**Use Case: Store Notes** + +***Preconditions:*** User has initiated adding or editing a contact. + +**MSS** + +1. User provides some notes for the contact. +2. System stores the notes with the contact’s information. + +***Postconditions:*** The contact's notes are stored or updated. - Use case ends. +___ **Extensions** From 0edb9fb3d4255d9da1fc76516fbce14c1f2a6173 Mon Sep 17 00:00:00 2001 From: Newton Koh Date: Tue, 12 Mar 2024 17:05:46 +0800 Subject: [PATCH 02/17] Remove duplicate use case and rename features --- docs/DeveloperGuide.md | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index bca1f6dacbe..ca4cdf4e2d9 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -324,21 +324,6 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli ___ -**Use case: Delete a person** - -***Preconditions:*** User is logged into the system. - -**MSS** - -1. User requests to list persons -2. AddressBook shows a list of persons -3. User requests to delete a specific person in the list -4. AddressBook deletes the person - -***Postconditions:*** A contact is deleted from the address book. - -___ - **Use Case: Add Contact** ***Preconditions:*** User is logged into the system. @@ -490,16 +475,16 @@ ___ ___ -**Use Case: Store Notes** +**Use Case: Store Remarks** ***Preconditions:*** User has initiated adding or editing a contact. **MSS** -1. User provides some notes for the contact. -2. System stores the notes with the contact’s information. +1. User provides some remarks for the contact. +2. System stores the remarks with the contact’s information. -***Postconditions:*** The contact's notes are stored or updated. +***Postconditions:*** The contact's remarks are stored or updated. ___ From be3341d269533df02ad0a1143e838eff1e137856 Mon Sep 17 00:00:00 2001 From: Newton Koh Date: Tue, 12 Mar 2024 17:43:06 +0800 Subject: [PATCH 03/17] Fix checkstyle issues --- .../address/logic/commands/RemarkCommand.java | 16 +++++++++------ .../logic/parser/AddressBookParser.java | 11 +++++++++- .../logic/parser/RemarkCommandParser.java | 20 ++++++++++++------- .../seedu/address/model/person/Remark.java | 3 +++ .../java/seedu/address/ui/PersonCard.java | 1 - 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index 585e6a97c83..dc7a0cd4349 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -1,5 +1,10 @@ package seedu.address.logic.commands; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import java.util.List; + import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; @@ -7,11 +12,6 @@ import seedu.address.model.person.Person; import seedu.address.model.person.Remark; -import java.util.List; - -import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; - /** * Changes the remark of an existing person in the address book. */ @@ -38,6 +38,10 @@ public class RemarkCommand extends Command { private final Index index; private final Remark remark; + /** + * @param index index of the contact + * @param remark string representing remark of contact + */ public RemarkCommand(Index index, Remark remark) { requireAllNonNull(index, remark.toString()); @@ -89,4 +93,4 @@ private String generateSuccessMessage(Person personToEdit) { String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS; return String.format(message, personToEdit); } -} \ No newline at end of file +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 9d310fdf629..6e23a66022b 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -8,7 +8,16 @@ import java.util.regex.Pattern; import seedu.address.commons.core.LogsCenter; -import seedu.address.logic.commands.*; +import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.ExitCommand; +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java index f1c26d49d53..28f16ec376a 100644 --- a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -1,19 +1,25 @@ package seedu.address.logic.parser; +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; + import seedu.address.commons.core.index.Index; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.*; -import seedu.address.model.tag.Tag; - - -import static java.util.Objects.requireNonNull; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; +import seedu.address.model.person.Remark; +/** + * Parser for the remark command + */ public class RemarkCommandParser implements Parser { + /** + * @param args argument to be parsed + * @return a RemarkCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ public RemarkCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, diff --git a/src/main/java/seedu/address/model/person/Remark.java b/src/main/java/seedu/address/model/person/Remark.java index 2e5c65280b9..b0e3cc7bb9e 100644 --- a/src/main/java/seedu/address/model/person/Remark.java +++ b/src/main/java/seedu/address/model/person/Remark.java @@ -9,6 +9,9 @@ public class Remark { public final String value; + /** + * @param remark string representing the remark of a contact + */ public Remark(String remark) { requireNonNull(remark); value = remark; diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 5fd521118fb..133b001267c 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -40,7 +40,6 @@ public class PersonCard extends UiPart { private Label email; @FXML private FlowPane tags; - @FXML private Label remark; From 44fe650f43aadef2046491e9db94a507302b0c29 Mon Sep 17 00:00:00 2001 From: Newton Koh Date: Tue, 12 Mar 2024 17:57:06 +0800 Subject: [PATCH 04/17] Include remark prefix --- src/main/java/seedu/address/logic/parser/CliSyntax.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf119..96be13b3772 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -11,5 +11,6 @@ public class CliSyntax { public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_REMARK = new Prefix("r/"); } From 72ea11011924cac929f5169b1e6786c3dcef05b5 Mon Sep 17 00:00:00 2001 From: Newton Koh Date: Tue, 12 Mar 2024 18:11:08 +0800 Subject: [PATCH 05/17] Fix conflicts on remark command --- .../address/logic/commands/EditCommand.java | 4 +- .../logic/parser/AddCommandParser.java | 4 +- .../seedu/address/model/person/Person.java | 9 +- .../address/model/util/SampleDataUtil.java | 15 +-- .../address/storage/JsonAdaptedPerson.java | 12 ++- src/main/resources/view/PersonListCard.fxml | 1 + .../duplicatePersonAddressBook.json | 4 +- .../typicalPersonsAddressBook.json | 7 ++ .../logic/commands/CommandTestUtil.java | 1 + .../logic/commands/RemarkCommandTest.java | 101 ++++++++++++++++++ .../storage/JsonAdaptedPersonTest.java | 23 ++-- .../seedu/address/testutil/PersonBuilder.java | 15 ++- .../address/testutil/TypicalPersons.java | 4 +- 13 files changed, 177 insertions(+), 23 deletions(-) create mode 100644 src/test/java/seedu/address/logic/commands/RemarkCommandTest.java diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4b581c7331e..d1a22957543 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -26,6 +26,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.tag.Tag; /** @@ -100,8 +101,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); + Remark updatedRemark = personToEdit.getRemark(); // edit command does not allow editing remarks - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRemark, updatedTags); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4ff1a97ed77..8963820cfab 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -17,6 +17,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.tag.Tag; /** @@ -43,9 +44,10 @@ public AddCommand parse(String args) throws ParseException { Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); + Remark remark = new Remark(""); // add command does not allow adding remarks straight away Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList); + Person person = new Person(name, phone, email, address, remark, tagList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..b09332dce6d 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -23,17 +23,19 @@ public class Person { // Data fields private final Address address; + private final Remark remark; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { + public Person(Name name, Phone phone, Email email, Address address, Remark remark, Set tags) { requireAllNonNull(name, phone, email, address, tags); this.name = name; this.phone = phone; this.email = email; this.address = address; + this.remark = remark; this.tags.addAll(tags); } @@ -53,6 +55,10 @@ public Address getAddress() { return address; } + public Remark getRemark() { + return remark; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -110,6 +116,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("address", address) + .add("remark", remark) .add("tags", tags) .toString(); } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..cd23c8beaed 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -11,31 +11,34 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.tag.Tag; /** * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { + + public static final Remark EMPTY_REMARK = new Remark(""); public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), + new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK, getTagSet("friends")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_REMARK, getTagSet("colleagues", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), EMPTY_REMARK, getTagSet("neighbours")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), EMPTY_REMARK, getTagSet("family")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), + new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK, getTagSet("classmates")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), + new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK, getTagSet("colleagues")) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index bd1ca0f56c8..a5a091e11a7 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -15,6 +15,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.tag.Tag; /** @@ -28,6 +29,7 @@ class JsonAdaptedPerson { private final String phone; private final String email; private final String address; + private final String remark; private final List tags = new ArrayList<>(); /** @@ -36,11 +38,13 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("remark") String remark, @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; this.address = address; + this.remark = remark; if (tags != null) { this.tags.addAll(tags); } @@ -54,6 +58,7 @@ public JsonAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; address = source.getAddress().value; + remark = source.getRemark().value; tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -102,8 +107,13 @@ public Person toModelType() throws IllegalValueException { } final Address modelAddress = new Address(address); + if (remark == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName())); + } + final Remark modelRemark = new Remark(remark); + final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelTags); } } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index f5e812e25e6..1bff2cd09eb 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -31,6 +31,7 @@