diff --git a/src/main/java/staffconnect/logic/Messages.java b/src/main/java/staffconnect/logic/Messages.java index 210b43d43e8..237754bf0e1 100644 --- a/src/main/java/staffconnect/logic/Messages.java +++ b/src/main/java/staffconnect/logic/Messages.java @@ -43,6 +43,8 @@ public static String format(Person person) { .append(person.getEmail()) .append("; Venue: ") .append(person.getVenue()) + .append("; Module: ") + .append(person.getModule()) .append("; Tags: "); person.getTags().forEach(builder::append); return builder.toString(); diff --git a/src/main/java/staffconnect/logic/commands/AddCommand.java b/src/main/java/staffconnect/logic/commands/AddCommand.java index 577b0f67521..e89a8a8ad1a 100644 --- a/src/main/java/staffconnect/logic/commands/AddCommand.java +++ b/src/main/java/staffconnect/logic/commands/AddCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -26,12 +27,14 @@ public class AddCommand extends Command { + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + PREFIX_VENUE + "VENUE " + + PREFIX_MODULE + "MODULE " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + PREFIX_VENUE + "311, Clementi Ave 2, #02-25 " + + PREFIX_MODULE + "CS2103 " + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; diff --git a/src/main/java/staffconnect/logic/commands/EditCommand.java b/src/main/java/staffconnect/logic/commands/EditCommand.java index 0b51e4aa99c..a2a253942d1 100644 --- a/src/main/java/staffconnect/logic/commands/EditCommand.java +++ b/src/main/java/staffconnect/logic/commands/EditCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -22,6 +23,7 @@ import staffconnect.logic.commands.exceptions.CommandException; import staffconnect.model.Model; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -43,6 +45,7 @@ public class EditCommand extends Command { + "[" + PREFIX_PHONE + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " + "[" + PREFIX_VENUE + "VENUE] " + + "[" + PREFIX_MODULE + "MODULE] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE + "91234567 " @@ -99,9 +102,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Venue updatedVenue = editPersonDescriptor.getVenue().orElse(personToEdit.getVenue()); + Module updatedModule = editPersonDescriptor.getModule().orElse(personToEdit.getModule()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedModule, updatedTags); } @Override @@ -137,6 +141,7 @@ public static class EditPersonDescriptor { private Phone phone; private Email email; private Venue venue; + private Module module; private Set tags; public EditPersonDescriptor() {} @@ -150,6 +155,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setPhone(toCopy.phone); setEmail(toCopy.email); setVenue(toCopy.venue); + setModule(toCopy.module); setTags(toCopy.tags); } @@ -157,7 +163,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, venue, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, venue, module, tags); } public void setName(Name name) { @@ -192,6 +198,14 @@ public Optional getVenue() { return Optional.ofNullable(venue); } + public void setModule(Module module) { + this.module = module; + } + + public Optional getModule() { + return Optional.ofNullable(module); + } + /** * Sets {@code tags} to this object's {@code tags}. * A defensive copy of {@code tags} is used internally. @@ -225,6 +239,7 @@ public boolean equals(Object other) { && Objects.equals(phone, otherEditPersonDescriptor.phone) && Objects.equals(email, otherEditPersonDescriptor.email) && Objects.equals(venue, otherEditPersonDescriptor.venue) + && Objects.equals(module, otherEditPersonDescriptor.module) && Objects.equals(tags, otherEditPersonDescriptor.tags); } @@ -235,6 +250,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("venue", venue) + .add("module", module) .add("tags", tags) .toString(); } diff --git a/src/main/java/staffconnect/logic/parser/AddCommandParser.java b/src/main/java/staffconnect/logic/parser/AddCommandParser.java index 19f8d8e203e..3b8bf5a2f62 100644 --- a/src/main/java/staffconnect/logic/parser/AddCommandParser.java +++ b/src/main/java/staffconnect/logic/parser/AddCommandParser.java @@ -2,6 +2,7 @@ import static staffconnect.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -13,6 +14,7 @@ import staffconnect.logic.commands.AddCommand; import staffconnect.logic.parser.exceptions.ParseException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -30,22 +32,24 @@ public class AddCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public AddCommand parse(String args) throws ParseException { - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_TAG); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, + PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_VENUE, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE); 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()); Venue venue = ParserUtil.parseVenue(argMultimap.getValue(PREFIX_VENUE).get()); + Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, venue, tagList); + Person person = new Person(name, phone, email, venue, module, tagList); return new AddCommand(person); } diff --git a/src/main/java/staffconnect/logic/parser/CliSyntax.java b/src/main/java/staffconnect/logic/parser/CliSyntax.java index 110c2dd1386..9493ab188e5 100644 --- a/src/main/java/staffconnect/logic/parser/CliSyntax.java +++ b/src/main/java/staffconnect/logic/parser/CliSyntax.java @@ -10,6 +10,7 @@ public class CliSyntax { public static final Prefix PREFIX_PHONE = new Prefix("p/"); public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_VENUE = new Prefix("v/"); + public static final Prefix PREFIX_MODULE = new Prefix("m/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); } diff --git a/src/main/java/staffconnect/logic/parser/EditCommandParser.java b/src/main/java/staffconnect/logic/parser/EditCommandParser.java index 76ff492730f..3249935c101 100644 --- a/src/main/java/staffconnect/logic/parser/EditCommandParser.java +++ b/src/main/java/staffconnect/logic/parser/EditCommandParser.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser { public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_TAG); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); Index index; @@ -42,7 +44,8 @@ public EditCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE); EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); @@ -58,6 +61,9 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_VENUE).isPresent()) { editPersonDescriptor.setVenue(ParserUtil.parseVenue(argMultimap.getValue(PREFIX_VENUE).get())); } + if (argMultimap.getValue(PREFIX_MODULE).isPresent()) { + editPersonDescriptor.setModule(ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get())); + } parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); if (!editPersonDescriptor.isAnyFieldEdited()) { diff --git a/src/main/java/staffconnect/logic/parser/ParserUtil.java b/src/main/java/staffconnect/logic/parser/ParserUtil.java index 182ab6e4755..454061da8b3 100644 --- a/src/main/java/staffconnect/logic/parser/ParserUtil.java +++ b/src/main/java/staffconnect/logic/parser/ParserUtil.java @@ -10,6 +10,7 @@ import staffconnect.commons.util.StringUtil; import staffconnect.logic.parser.exceptions.ParseException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Phone; import staffconnect.model.person.Venue; @@ -65,6 +66,21 @@ public static Phone parsePhone(String phone) throws ParseException { return new Phone(trimmedPhone); } + /** + * Parses a {@code String email} into an {@code Email}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code email} is invalid. + */ + public static Email parseEmail(String email) throws ParseException { + requireNonNull(email); + String trimmedEmail = email.trim(); + if (!Email.isValidEmail(trimmedEmail)) { + throw new ParseException(Email.MESSAGE_CONSTRAINTS); + } + return new Email(trimmedEmail); + } + /** * Parses a {@code String venue} into an {@code Venue}. * Leading and trailing whitespaces will be trimmed. @@ -81,18 +97,18 @@ public static Venue parseVenue(String venue) throws ParseException { } /** - * Parses a {@code String email} into an {@code Email}. + * Parses a {@code String module} into an {@code Module}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code email} is invalid. + * @throws ParseException if the given {@code module} is invalid. */ - public static Email parseEmail(String email) throws ParseException { - requireNonNull(email); - String trimmedEmail = email.trim(); - if (!Email.isValidEmail(trimmedEmail)) { - throw new ParseException(Email.MESSAGE_CONSTRAINTS); + public static Module parseModule(String module) throws ParseException { + requireNonNull(module); + String trimmedModule = module.trim(); + if (!Module.isValidModule(trimmedModule)) { + throw new ParseException(Module.MESSAGE_CONSTRAINTS); } - return new Email(trimmedEmail); + return new Module(trimmedModule); } /** diff --git a/src/main/java/staffconnect/model/person/Name.java b/src/main/java/staffconnect/model/person/Name.java index e1d9e927aa3..538b1e28e78 100644 --- a/src/main/java/staffconnect/model/person/Name.java +++ b/src/main/java/staffconnect/model/person/Name.java @@ -13,7 +13,7 @@ public class Name { "Names should only contain alphanumeric characters and spaces, and it should not be blank"; /* - * The first character of the address must not be a whitespace, + * The first character of the name must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; diff --git a/src/main/java/staffconnect/model/person/Person.java b/src/main/java/staffconnect/model/person/Person.java index 58424f05908..5c10209078e 100644 --- a/src/main/java/staffconnect/model/person/Person.java +++ b/src/main/java/staffconnect/model/person/Person.java @@ -23,17 +23,19 @@ public class Person { // Data fields private final Venue venue; + private final Module module; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Venue venue, Set tags) { - requireAllNonNull(name, phone, email, venue, tags); + public Person(Name name, Phone phone, Email email, Venue venue, Module module, Set tags) { + requireAllNonNull(name, phone, email, venue, module, tags); this.name = name; this.phone = phone; this.email = email; this.venue = venue; + this.module = module; this.tags.addAll(tags); } @@ -53,6 +55,10 @@ public Venue getVenue() { return venue; } + public Module getModule() { + return module; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -94,13 +100,14 @@ public boolean equals(Object other) { && phone.equals(otherPerson.phone) && email.equals(otherPerson.email) && venue.equals(otherPerson.venue) + && module.equals(otherPerson.module) && tags.equals(otherPerson.tags); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, venue, tags); + return Objects.hash(name, phone, email, venue, module, tags); } @Override @@ -110,6 +117,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("venue", venue) + .add("module", module) .add("tags", tags) .toString(); } diff --git a/src/main/java/staffconnect/model/util/SampleDataUtil.java b/src/main/java/staffconnect/model/util/SampleDataUtil.java index b9704a48308..1befd734f31 100644 --- a/src/main/java/staffconnect/model/util/SampleDataUtil.java +++ b/src/main/java/staffconnect/model/util/SampleDataUtil.java @@ -7,6 +7,7 @@ import staffconnect.model.ReadOnlyStaffBook; import staffconnect.model.StaffBook; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -20,23 +21,23 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Venue("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), + new Venue("Blk 30 Geylang Street 29, #06-40"), new Module("CS1101S"), + getTagSet("professor")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Venue("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), + new Venue("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new Module("CS1231S"), + getTagSet("tutor", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Venue("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), + new Venue("Blk 11 Ang Mo Kio Street 74, #11-04"), new Module("CS2030S"), + getTagSet("professor")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Venue("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), + new Venue("Blk 436 Serangoon Gardens Street 26, #16-43"), new Module("CS2040S"), + getTagSet("professor")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Venue("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), + new Venue("Blk 47 Tampines Street 20, #17-35"), new Module("CS2100"), + getTagSet("tutor")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Venue("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) + new Venue("Blk 45 Aljunied Street 85, #11-31"), new Module("CS2101"), + getTagSet("professor")) }; } diff --git a/src/main/java/staffconnect/storage/JsonAdaptedPerson.java b/src/main/java/staffconnect/storage/JsonAdaptedPerson.java index dd5958ff973..600299c7a12 100644 --- a/src/main/java/staffconnect/storage/JsonAdaptedPerson.java +++ b/src/main/java/staffconnect/storage/JsonAdaptedPerson.java @@ -11,6 +11,7 @@ import staffconnect.commons.exceptions.IllegalValueException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -28,6 +29,7 @@ class JsonAdaptedPerson { private final String phone; private final String email; private final String venue; + private final String module; private final List tags = new ArrayList<>(); /** @@ -36,11 +38,12 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("venue") String venue, - @JsonProperty("tags") List tags) { + @JsonProperty("module") String module, @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; this.venue = venue; + this.module = module; if (tags != null) { this.tags.addAll(tags); } @@ -54,6 +57,7 @@ public JsonAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; venue = source.getVenue().value; + module = source.getModule().value; tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -102,8 +106,16 @@ public Person toModelType() throws IllegalValueException { } final Venue modelVenue = new Venue(venue); + if (module == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Module.class.getSimpleName())); + } + if (!Module.isValidModule(module)) { + throw new IllegalValueException(Module.MESSAGE_CONSTRAINTS); + } + final Module modelModule = new Module(module); + final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelVenue, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelVenue, modelModule, modelTags); } } diff --git a/src/main/java/staffconnect/ui/PersonCard.java b/src/main/java/staffconnect/ui/PersonCard.java index 0abadaa1092..f93f79e7476 100644 --- a/src/main/java/staffconnect/ui/PersonCard.java +++ b/src/main/java/staffconnect/ui/PersonCard.java @@ -37,6 +37,8 @@ public class PersonCard extends UiPart { @FXML private Label venue; @FXML + private Label module; + @FXML private Label email; @FXML private FlowPane tags; @@ -51,6 +53,7 @@ public PersonCard(Person person, int displayedIndex) { name.setText(person.getName().fullName); phone.setText(person.getPhone().value); venue.setText(person.getVenue().value); + module.setText(person.getModule().value); email.setText(person.getEmail().value); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 7778f666a0a..bdfd006114b 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -12,7 +12,7 @@ + title="StaffConnect App" minWidth="450" minHeight="600" onCloseRequest="#handleExit"> diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index c75735e6b23..2101c6c5ed9 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -30,6 +30,7 @@