From cbfa2b94c7bf061b08086b307db043f78b3cae72 Mon Sep 17 00:00:00 2001 From: erv-teo <107994607+erv-teo@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:08:37 +0800 Subject: [PATCH 01/20] Recognize remark command --- .../address/logic/commands/RemarkCommand.java | 9 ++++ .../logic/parser/AddressBookParser.java | 3 ++ .../logic/parser/RemarkCommandParser.java | 2 + .../seedu/address/model/person/Remark.java | 2 + .../address/model/util/SampleDataUtil.java | 48 ++++++++++++++----- .../logic/commands/RemarkCommandTest.java | 2 + 6 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/RemarkCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/RemarkCommandParser.java create mode 100644 src/main/java/seedu/address/model/person/Remark.java create mode 100644 src/test/java/seedu/address/logic/commands/RemarkCommandTest.java diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java new file mode 100644 index 00000000000..d05a31d2c74 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -0,0 +1,9 @@ +package seedu.address.logic.commands; +import seedu.address.model.Model; +public class RemarkCommand extends Command { + public static final String COMMAND_WORD = "remark"; + @Override + public CommandResult execute(Model model) { + return new CommandResult("Hello from remark"); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 3149ee07e0b..128b5dca866 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -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; /** @@ -76,6 +77,8 @@ public Command parseCommand(String userInput) throws ParseException { case HelpCommand.COMMAND_WORD: return new HelpCommand(); + case RemarkCommand.COMMAND_WORD: + return new RemarkCommand(); default: logger.finer("This user input caused a ParseException: " + userInput); diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java new file mode 100644 index 00000000000..041e7dd2334 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -0,0 +1,2 @@ +package seedu.address.logic.parser;public class RemarkCommandParser { +} diff --git a/src/main/java/seedu/address/model/person/Remark.java b/src/main/java/seedu/address/model/person/Remark.java new file mode 100644 index 00000000000..ed68866e659 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Remark.java @@ -0,0 +1,2 @@ +package seedu.address.model.person;public class Remark { +} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 4ffb9b353ea..354cb4eae52 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -20,18 +20,42 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[]{ - new Person(new Name("Alex Yeoh"), getTagSet("Diabetes"), new Dob("01/01/1990"), - new Ic("S1234567A"), new AdmissionDate("01/01/2022"), new Ward("Ward A")), - new Person(new Name("Bernice Yu"), getTagSet("FallRisk", "Diabetes"), new Dob("01/01/1990"), - new Ic("S1234567A"), new AdmissionDate("02/01/2022"), new Ward("Ward B")), - new Person(new Name("Charlotte Oliveiro"), getTagSet("FallRisk"), new Dob("01/01/1990"), - new Ic("S1234567A"), new AdmissionDate("03/01/2022"), new Ward("Ward C")), - new Person(new Name("David Li"), getTagSet("Dementia"), new Dob("01/01/1990"), - new Ic("S1234567A"), new AdmissionDate("04/01/2022"), new Ward("Ward D")), - new Person(new Name("Irfan Ibrahim"), getTagSet("NPO"), new Dob("01/01/1990"), - new Ic("S1234567A"), new AdmissionDate("05/01/2022"), new Ward("Ward E")), - new Person(new Name("Roy Balakrishnan"), getTagSet("Dementia"), new Dob("01/01/1990"), - new Ic("S1234567A"), new AdmissionDate("Bed Rest"), new Ward("Ward F")) + new Person(new Name("Alex Yeoh"), + getTagSet("Diabetes"), + new Dob("01/01/1990"), + new Ic("S1234567A"), + new AdmissionDate("01/01/2022"), + new Ward("Ward A")), + new Person(new Name("Bernice Yu"), + getTagSet("FallRisk", "Diabetes"), + new Dob("01/01/1990"), + new Ic("S1234567A"), + new AdmissionDate("02/01/2022"), + new Ward("Ward B")), + new Person(new Name("Charlotte Oliveiro"), + getTagSet("FallRisk"), + new Dob("01/01/1990"), + new Ic("S1234567A"), + new AdmissionDate("03/01/2022"), + new Ward("Ward C")), + new Person(new Name("David Li"), + getTagSet("Dementia"), + new Dob("01/01/1990"), + new Ic("S1234567A"), + new AdmissionDate("04/01/2022"), + new Ward("Ward D")), + new Person(new Name("Irfan Ibrahim"), + getTagSet("NPO"), + new Dob("01/01/1990"), + new Ic("S1234567A"), + new AdmissionDate("05/01/2022"), + new Ward("Ward E")), + new Person(new Name("Roy Balakrishnan"), + getTagSet("Dementia"), + new Dob("01/01/1990"), + new Ic("S1234567A"), + new AdmissionDate("14/03/2024"), + new Ward("Ward F")) }; } diff --git a/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java new file mode 100644 index 00000000000..a181c5eeaf6 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java @@ -0,0 +1,2 @@ +package seedu.address.logic.commands;public class RemarkCommandTest { +} From e6273632a35d3f146b7b87f5e80bbfc4c498191c Mon Sep 17 00:00:00 2001 From: erv-teo <107994607+erv-teo@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:11:40 +0800 Subject: [PATCH 02/20] Remark throws not implemented error --- .../address/logic/commands/RemarkCommand.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index d05a31d2c74..691a8f0e055 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -1,9 +1,22 @@ package seedu.address.logic.commands; import seedu.address.model.Model; +import seedu.address.logic.commands.exceptions.CommandException; 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_NOT_IMPLEMENTED_YET = + "Remark command not implemented yet"; + @Override - public CommandResult execute(Model model) { - return new CommandResult("Hello from remark"); + public CommandResult execute(Model model) throws CommandException { + throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET); } } From e7c5af7c2a7f939b3cbffca129394e6305616838 Mon Sep 17 00:00:00 2001 From: erv-teo <107994607+erv-teo@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:24:11 +0800 Subject: [PATCH 03/20] Add placeholder for remark --- .../address/logic/commands/RemarkCommand.java | 39 +++++++++++++++- .../logic/parser/AddressBookParser.java | 2 +- .../seedu/address/logic/parser/CliSyntax.java | 1 + .../logic/parser/RemarkCommandParser.java | 41 ++++++++++++++++- .../seedu/address/model/person/Remark.java | 45 ++++++++++++++++++- .../java/seedu/address/ui/PersonCard.java | 3 ++ src/main/resources/view/PersonListCard.fxml | 1 + 7 files changed, 128 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index 691a8f0e055..dc9112174a5 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -1,6 +1,11 @@ package seedu.address.logic.commands; +import seedu.address.commons.core.index.Index; import seedu.address.model.Model; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.person.Remark; + +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + public class RemarkCommand extends Command { public static final String COMMAND_WORD = "remark"; public static final String MESSAGE_USAGE = COMMAND_WORD @@ -12,11 +17,43 @@ public class RemarkCommand extends Command { + "Example: " + COMMAND_WORD + " 1 " + "r/ Likes to swim."; + public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; + + private final Index index; + private final Remark remark; public static final String MESSAGE_NOT_IMPLEMENTED_YET = "Remark command not implemented yet"; + /** + * @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 { - throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET); + throw new CommandException( + String.format(MESSAGE_ARGUMENTS, index.getOneBased(), remark)); + } + + @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); } } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 128b5dca866..455f159118f 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -78,7 +78,7 @@ public Command parseCommand(String userInput) throws ParseException { case HelpCommand.COMMAND_WORD: return new HelpCommand(); case RemarkCommand.COMMAND_WORD: - return new RemarkCommand(); + return new RemarkCommandParser().parse(arguments); default: logger.finer("This user input caused a ParseException: " + userInput); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 4b797463a48..f6df528f8c4 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -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\\"); } diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java index 041e7dd2334..bee11e9c13a 100644 --- a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -1,2 +1,41 @@ -package seedu.address.logic.parser;public class RemarkCommandParser { +package seedu.address.logic.parser; + +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; + +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; + +/** + * Parses input arguments and creates a new RemarkCommand object + */ +public class RemarkCommandParser implements Parser { + + /** + * 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); + } } diff --git a/src/main/java/seedu/address/model/person/Remark.java b/src/main/java/seedu/address/model/person/Remark.java index ed68866e659..8c987fc7e90 100644 --- a/src/main/java/seedu/address/model/person/Remark.java +++ b/src/main/java/seedu/address/model/person/Remark.java @@ -1,2 +1,45 @@ -package seedu.address.model.person;public class Remark { +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Person's remarks in the address book. + */ +public class Remark { + public final String value; + + /** + * Constructs an {@code Remark}. + * + * @param value A valid remark. + */ + public Remark(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Remark)) { + return false; + } + + Remark otherRemark = (Remark) other; + return value.equals(otherRemark.value); + } + + @Override + public int hashCode() { + return value.hashCode(); + } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 4623e28aecc..0cb06b9785b 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -41,6 +41,8 @@ public class PersonCard extends UiPart { private Label ward; @FXML private FlowPane tags; + @FXML + private Label remark; /** @@ -58,5 +60,6 @@ public PersonCard(Person person, int displayedIndex) { person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); +// remark.setText("Remark: " + person.getRemark().value); } } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 3b122f0a4ce..42bf7641dfe 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -32,6 +32,7 @@