Skip to content

Commit

Permalink
Merge pull request #166 from songfangyl/branch-add-remark-feature
Browse files Browse the repository at this point in the history
Add remark feature
  • Loading branch information
yucongkoo authored Oct 26, 2023
2 parents a659352 + 0a15b28 commit d3271d4
Show file tree
Hide file tree
Showing 26 changed files with 569 additions and 72 deletions.
1 change: 0 additions & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class MainApp extends Application {
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());
initLogging(config);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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.priority.Priority;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -105,10 +106,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Remark remark = personToEdit.getRemark();
Set<Tag> tags = personToEdit.getTags();
Priority priority = personToEdit.getPriority();

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, tags, priority);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, remark, tags, priority);
}

@Override
Expand Down
93 changes: 93 additions & 0 deletions src/main/java/seedu/address/logic/commands/RemarkCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.person.Remark;


/**
* Remark a person.
*/
public class RemarkCommand extends Command {


public static final String COMMAND_WORD = "remark";
public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s";
public static final String MESSAGE_ADD_REMARK_SUCCESS = "Added remark to Person: %1$s";
public static final String MESSAGE_DELETE_REMARK_SUCCESS = "Removed remark from Person: %1$s";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits the remark of the person identified "
+ "by the index number used in the last person listing. "
+ "Existing remark will be overwritten by the input.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "r/ [REMARK]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ "r/ Likes to swim.";
private final Index index;
private final Remark remark;


/**
* @param index of the person in the filtered person list to edit the remark
* @param remark of the person to be updated to
*/
public RemarkCommand(Index index, Remark remark) {
requireAllNonNull(index, remark);

this.index = index;
this.remark = remark;
}
@Override
public CommandResult execute(Model model) throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = new Person(
personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(),
personToEdit.getAddress(), remark, personToEdit.getTags(), personToEdit.getPriority());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

return new CommandResult(generateSuccessMessage(editedPerson));
}

/**
* Generates a command execution success message based on whether
* the remark is added to or removed from
* {@code personToEdit}.
*/
private String generateSuccessMessage(Person personToEdit) {
String message = !remark.toString().isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS;
return String.format(message, personToEdit);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof RemarkCommand)) {
return false;
}

RemarkCommand e = (RemarkCommand) other;
return index.equals(e.index)
&& remark.equals(e.remark);
}
}
12 changes: 7 additions & 5 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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_PRIORITY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Set;
Expand All @@ -20,6 +21,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.priority.Priority;
import seedu.address.model.tag.Tag;

Expand All @@ -37,26 +39,26 @@ public AddCommand parse(String args) throws ParseException {
requireNonNull(args);

ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_PRIORITY);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_REMARK, PREFIX_TAG, PREFIX_PRIORITY);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_PRIORITY);

PREFIX_REMARK, PREFIX_PRIORITY);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Remark remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).orElse(""));
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).orElse(null));
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Priority priority = ParserUtil.parsePriority(argMultimap.getValue(PREFIX_PRIORITY)
.orElse(Priority.NONE_PRIORITY_KEYWORD));

Person person = new Person(name, phone, email, address, tagList, priority);
Person person = new Person(name, phone, email, address, remark, tagList, priority);

requireAllNonNull(name, phone, email, address, tagList, person);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.PriorityCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.commands.TagCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand Down Expand Up @@ -79,6 +80,9 @@ public Command parseCommand(String userInput) throws ParseException {
case HelpCommand.COMMAND_WORD:
return new HelpCommand();

case RemarkCommand.COMMAND_WORD:
return new RemarkCommandParser().parse(arguments);

case TagCommand.COMMAND_WORD:
return new TagCommandParser().parse(arguments);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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/");
public static final Prefix PREFIX_ADD_TAG = new Prefix("at/");
public static final Prefix PREFIX_DELETE_TAG = new Prefix("dt/");
public static final Prefix PREFIX_PRIORITY = new Prefix("pr/");
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.NonEmptyAddress;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.priority.Priority;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -144,4 +145,19 @@ public static Priority parsePriority(String priority) throws ParseException {
}
return new Priority(trimmedPriority);
}

/**
* Parses a {@code String priority} into a {@code Priority}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code priority} is invalid.
*/
public static Remark parseRemark(String remark) throws ParseException {
requireNonNull(remark);
String trimmedRemark = remark.trim();
if (!Remark.isValidRemark(trimmedRemark)) {
throw new ParseException((Remark.MESSAGE_CONSTRAINTS));
}
return new Remark(trimmedRemark);
}
}
45 changes: 45 additions & 0 deletions src/main/java/seedu/address/logic/parser/RemarkCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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.Remark;


/**
* Parses input arguments and creates a new RemarkCommand object
*/
public class RemarkCommandParser implements Parser<RemarkCommand> {

/**
* Parses input and return the RemarkCommand object.
*
* @param args Input string.
* @return Corresponding RemarkCommand Object.
* @throws ParseException When there is an exception.
*/
public RemarkCommand parse(String args) throws ParseException {
requireNonNull(args);

ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args,
PREFIX_REMARK);

Index index;
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
RemarkCommand.MESSAGE_USAGE), ive);
}

Remark remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).orElse(""));

return new RemarkCommand(index, remark);
}

}
27 changes: 20 additions & 7 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,35 @@ public class Person {

// Data fields
private final Address address;
private final Remark remark;
private final Set<Tag> tags = new HashSet<>();
private final Priority priority;

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
public Person(Name name, Phone phone, Email email, Address address, Remark remark, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, remark, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.remark = remark;
this.tags.addAll(tags);
this.priority = new Priority(Priority.NONE_PRIORITY_KEYWORD);
}

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Priority priority) {
requireAllNonNull(name, phone, email, address, tags, priority);
public Person(Name name, Phone phone, Email email, Address address,
Remark remark, Set<Tag> tags, Priority priority) {
requireAllNonNull(name, phone, email, address, remark, tags, priority);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.remark = remark;
this.tags.addAll(tags);
this.priority = priority;
}
Expand All @@ -70,8 +74,13 @@ public Address getAddress() {
return address;
}

public Remark getRemark() {
return remark;
}

public Priority getPriority() {
return priority;

}

/**
Expand Down Expand Up @@ -115,7 +124,8 @@ public static Person createPersonWithUpdatedTags(Person source,
updatedTags.removeAll(tagsToDelete);
updatedTags.addAll(tagsToAdd);

return new Person(source.name, source.phone, source.email, source.address, updatedTags, source.priority);
return new Person(source.name, source.phone, source.email, source.address,
source.remark, updatedTags, source.priority);
}

/**
Expand All @@ -124,7 +134,8 @@ public static Person createPersonWithUpdatedTags(Person source,
*/
public static Person createPersonWithUpdatedPriority(Person source, Priority newPriority) {
requireAllNonNull(source, newPriority);
return new Person(source.name, source.phone, source.email, source.address, source.tags, newPriority);
return new Person(source.name, source.phone, source.email, source.address,
source.remark, source.tags, newPriority);
}

/**
Expand Down Expand Up @@ -154,14 +165,15 @@ public boolean equals(Object other) {
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& remark.equals(otherPerson.remark)
&& tags.equals(otherPerson.tags)
&& priority.equals(otherPerson.priority);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, tags, priority);
return Objects.hash(name, phone, email, address, remark, tags, priority);
}

@Override
Expand All @@ -171,6 +183,7 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("remark", remark)
.add("tags", tags)
.add("priority", priority)
.toString();
Expand Down
Loading

0 comments on commit d3271d4

Please sign in to comment.