Skip to content
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

Merged
merged 23 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public static String format(Person person) {
.append("\n Admitted: ")
.append(person.getAdmissionDate())
.append("\n Tags: ");

person.getTags().forEach(builder::append);
builder.append("\n Remarks: ")
.append(person.getRemark());
return builder.toString();
Copy link

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?

public static String format(Person person) {
        final StringBuilder builder = new StringBuilder();
        builder.append(person.getName())
                .append("\n IC: ")
                .append(person.getIc())
                .append("\n DOB: ")
                .append(person.getDob())
                .append("\n Ward: ")
                .append(person.getWard())
                .append("\n Admitted: ")
                .append(person.getAdmissionDate())
                .append("\n Remarks: ")
                .append(person.getRemark());
                .append("\n Tags: ");

        person.getTags().forEach(builder::append);
        return builder.toString();

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class AddCommand extends Command {
+ PREFIX_NAME + "NAME "
+ PREFIX_IC + "IC "
+ PREFIX_DOB + "DOB "
+ PREFIX_ADMISSION_DATE + "ADMISSION DATE "
+ PREFIX_WARD + "WARD NUMBER "
+ PREFIX_ADMISSION_DATE + "ADMISSION_DATE "
+ PREFIX_WARD + "WARD_NUMBER "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
Expand All @@ -27,6 +28,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;

Expand All @@ -47,6 +49,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_WARD + "WARD] "
+ "[" + PREFIX_ADMISSION_DATE + "ADMISSION DATE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_REMARK + "REMARK]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_IC + "T123456Q "
+ PREFIX_DOB + "12/08/1999";
Expand Down Expand Up @@ -105,8 +108,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
AdmissionDate updatedAdmissionDate =
editPersonDescriptor.getAdmissionDate().orElse(personToEdit.getAdmissionDate());
Ward updatedWard = editPersonDescriptor.getWard().orElse(personToEdit.getWard());
Remark updatedRemark = editPersonDescriptor.getRemark().orElse(personToEdit.getRemark());

return new Person(updatedName, updatedTags, updatedDob, updatedIc, updatedAdmissionDate, updatedWard);
return new Person(updatedName, updatedTags, updatedDob, updatedIc, updatedAdmissionDate,
updatedWard, updatedRemark);
}

@Override
Expand Down Expand Up @@ -144,7 +149,7 @@ public static class EditPersonDescriptor {
private Dob dob;
private AdmissionDate admissionDate;
private Ward ward;

private Remark remark;
public EditPersonDescriptor() {}

/**
Expand All @@ -158,6 +163,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setIc(toCopy.ic);
setAdmissionDate(toCopy.admissionDate);
setWard(toCopy.ward);
setRemark(toCopy.remark);
}

/**
Expand Down Expand Up @@ -215,6 +221,12 @@ public void setWard(Ward ward) {
public Optional<Ward> getWard() {
return Optional.ofNullable(ward);
}
public void setRemark(Remark remark) {
this.remark = remark;
}
public Optional<Remark> getRemark() {
return Optional.ofNullable(remark);
}
@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -232,19 +244,21 @@ public boolean equals(Object other) {
&& Objects.equals(ic, otherEditPersonDescriptor.ic)
&& Objects.equals(dob, otherEditPersonDescriptor.dob)
&& Objects.equals(admissionDate, otherEditPersonDescriptor.admissionDate)
&& Objects.equals(ward, otherEditPersonDescriptor.ward);
&& Objects.equals(ward, otherEditPersonDescriptor.ward)
&& Objects.equals(remark, otherEditPersonDescriptor.remark);

}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
.add("tags", tags)
.add("ic", ic)
.add("dob", dob)
.add("ic", ic)
.add("tags", tags)
.add("admissionDate", admissionDate)
.add("ward", ward)
.add("remark", remark)
.toString();
}
}
Expand Down
94 changes: 94 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,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
Copy link

Choose a reason for hiding this comment

The 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
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

The 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

/**
Expand Down Expand Up @@ -76,6 +77,8 @@

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

Check warning on line 81 in src/main/java/seedu/address/logic/parser/AddressBookParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddressBookParser.java#L81

Added line #L81 was not covered by tests

default:
logger.finer("This user input caused a ParseException: " + userInput);
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,4 +12,5 @@ public class CliSyntax {
public static final Prefix PREFIX_WARD = new Prefix("w\\");
public static final Prefix PREFIX_IC = new Prefix("ic\\");
public static final Prefix PREFIX_ADMISSION_DATE = new Prefix("ad\\");
public static final Prefix PREFIX_REMARK = new Prefix("r\\");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;

Expand Down Expand Up @@ -34,7 +35,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DOB, PREFIX_WARD, PREFIX_IC,
PREFIX_ADMISSION_DATE, PREFIX_TAG);
PREFIX_ADMISSION_DATE, PREFIX_TAG, PREFIX_REMARK);

Index index;

Expand Down Expand Up @@ -67,6 +68,10 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setWard(ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).get()));
}

if (argMultimap.getValue(PREFIX_REMARK).isPresent()) {
editPersonDescriptor.setRemark(ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get()));
}

if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.model.person.Dob;
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -141,4 +142,14 @@ public static Ward parseWard(String ward) throws ParseException {
return new Ward(trimmedWard);
}

/**
* Parses a {@code String remark} into a {@code Remark}.
* Leading and trailing whitespaces will be trimmed.
*/
public static Remark parseRemark(String remark) throws ParseException {
requireNonNull(remark);
String trimmedRemark = remark.trim();
return new Remark(trimmedRemark);
}

}
43 changes: 43 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,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> {

Check warning on line 18 in src/main/java/seedu/address/logic/parser/RemarkCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/RemarkCommandParser.java#L18

Added line #L18 was not covered by tests

/**
* 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,

Check warning on line 28 in src/main/java/seedu/address/logic/parser/RemarkCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/RemarkCommandParser.java#L27-L28

Added lines #L27 - L28 were not covered by tests
PREFIX_REMARK);

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

Check warning on line 35 in src/main/java/seedu/address/logic/parser/RemarkCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/RemarkCommandParser.java#L33-L35

Added lines #L33 - L35 were not covered by tests
RemarkCommand.MESSAGE_USAGE), ive);
}

Check warning on line 37 in src/main/java/seedu/address/logic/parser/RemarkCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/RemarkCommandParser.java#L37

Added line #L37 was not covered by tests

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

Check warning on line 39 in src/main/java/seedu/address/logic/parser/RemarkCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/RemarkCommandParser.java#L39

Added line #L39 was not covered by tests

return new RemarkCommand(index, remark);

Check warning on line 41 in src/main/java/seedu/address/logic/parser/RemarkCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/RemarkCommandParser.java#L41

Added line #L41 was not covered by tests
}
}
Loading
Loading