-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add remark feature #63
Changes from 13 commits
cbfa2b9
e627363
e7c5af7
a996065
1981250
5c7cf97
9d16707
45cfaed
6b97aef
bd61835
a1afb90
69e9b55
ff45099
b7e319e
63de80d
9ea25ea
8f33c5d
3b9ac9c
ca9c55b
8a97fe7
d47a4b0
ddbf058
063f62a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
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; | ||
|
||
|
||
|
||
/** | ||
* Changes the remark of an existing person in the address book. | ||
*/ | ||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this allow adding of remarks? More detail here would be good |
||
public class RemarkCommand extends Command { | ||
public static final String COMMAND_WORD = "remark"; | ||
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."; | ||
|
||
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"; | ||
|
||
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.getTags(), personToEdit.getDob(), | ||
personToEdit.getIc(), personToEdit.getAdmissionDate(), personToEdit.getWard(), | ||
remark); | ||
|
||
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.value.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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import seedu.address.model.person.Ic; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Remark; | ||
import seedu.address.model.person.Ward; | ||
import seedu.address.model.tag.Tag; | ||
|
||
|
@@ -50,9 +51,8 @@ public AddCommand parse(String args) throws ParseException { | |
AdmissionDate admissionDate = | ||
ParserUtil.parseAdmissionDate(argMultimap.getValue(PREFIX_ADMISSION_DATE).orElse(null)); | ||
Ward ward = ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).orElse(null)); | ||
|
||
|
||
Person person = new Person(name, tagList, dob, ic, admissionDate, ward); | ||
Remark remark = new Remark(""); | ||
Person person = new Person(name, tagList, dob, ic, admissionDate, ward, remark); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we having a parseRemark() method for this? Or remarks have to be added seperately. |
||
|
||
return new AddCommand(person); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 the given {@code String} of arguments in the context of the RemarkCommand | ||
* and returns an RemarkCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
@Override | ||
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 = new Remark(argMultimap.getValue(PREFIX_REMARK).orElse("")); | ||
|
||
return new RemarkCommand(index, remark); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit, but do you wanna do this instead?