Skip to content

Commit

Permalink
Merge pull request #75 from JerryWang0000/use-Faculty
Browse files Browse the repository at this point in the history
Update code to use `Faculty` attribute
  • Loading branch information
whitesnowx authored Mar 16, 2024
2 parents 712b8fa + cea9d93 commit 4c0e50a
Show file tree
Hide file tree
Showing 29 changed files with 348 additions and 98 deletions.
2 changes: 2 additions & 0 deletions src/main/java/staffconnect/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static String format(Person person) {
.append("; Phone: ")
.append(person.getPhone())
.append("; Email: ")
.append(person.getFaculty())
.append("; Faculty: ")
.append(person.getEmail())
.append("; Venue: ")
.append(person.getVenue())
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/staffconnect/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_FACULTY;
import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE;
import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME;
import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -26,13 +27,15 @@ public class AddCommand extends Command {
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_FACULTY + "FACULTY "
+ PREFIX_VENUE + "VENUE "
+ PREFIX_MODULE + "MODULE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_FACULTY + "Computing "
+ PREFIX_VENUE + "311, Clementi Ave 2, #02-25 "
+ PREFIX_MODULE + "CS2103 "
+ PREFIX_TAG + "friends "
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/staffconnect/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_FACULTY;
import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE;
import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME;
import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -23,6 +24,7 @@
import staffconnect.logic.commands.exceptions.CommandException;
import staffconnect.model.Model;
import staffconnect.model.person.Email;
import staffconnect.model.person.Faculty;
import staffconnect.model.person.Module;
import staffconnect.model.person.Name;
import staffconnect.model.person.Person;
Expand All @@ -44,6 +46,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_FACULTY + "FACULTY] "
+ "[" + PREFIX_VENUE + "VENUE] "
+ "[" + PREFIX_MODULE + "MODULE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
Expand Down Expand Up @@ -101,11 +104,13 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Faculty updatedFaculty = editPersonDescriptor.getFaculty().orElse(personToEdit.getFaculty());
Venue updatedVenue = editPersonDescriptor.getVenue().orElse(personToEdit.getVenue());
Module updatedModule = editPersonDescriptor.getModule().orElse(personToEdit.getModule());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedModule, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedFaculty,
updatedVenue, updatedModule, updatedTags);
}

@Override
Expand Down Expand Up @@ -140,6 +145,7 @@ public static class EditPersonDescriptor {
private Name name;
private Phone phone;
private Email email;
private Faculty faculty;
private Venue venue;
private Module module;
private Set<Tag> tags;
Expand All @@ -154,6 +160,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setFaculty(toCopy.faculty);
setVenue(toCopy.venue);
setModule(toCopy.module);
setTags(toCopy.tags);
Expand All @@ -163,7 +170,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, venue, module, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, faculty, venue, module, tags);
}

public void setName(Name name) {
Expand All @@ -190,6 +197,14 @@ public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}

public void setFaculty(Faculty faculty) {
this.faculty = faculty;
}

public Optional<Faculty> getFaculty() {
return Optional.ofNullable(faculty);
}

public void setVenue(Venue venue) {
this.venue = venue;
}
Expand Down Expand Up @@ -238,6 +253,7 @@ public boolean equals(Object other) {
return Objects.equals(name, otherEditPersonDescriptor.name)
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(faculty, otherEditPersonDescriptor.faculty)
&& Objects.equals(venue, otherEditPersonDescriptor.venue)
&& Objects.equals(module, otherEditPersonDescriptor.module)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
Expand All @@ -249,6 +265,7 @@ public String toString() {
.add("name", name)
.add("phone", phone)
.add("email", email)
.add("faculty", faculty)
.add("venue", venue)
.add("module", module)
.add("tags", tags)
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/staffconnect/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_FACULTY;
import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE;
import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME;
import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -14,6 +15,7 @@
import staffconnect.logic.commands.AddCommand;
import staffconnect.logic.parser.exceptions.ParseException;
import staffconnect.model.person.Email;
import staffconnect.model.person.Faculty;
import staffconnect.model.person.Module;
import staffconnect.model.person.Name;
import staffconnect.model.person.Person;
Expand All @@ -33,23 +35,24 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG);
PREFIX_EMAIL, PREFIX_FACULTY, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE)
|| !argMultimap.getPreamble().isEmpty()) {
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY,
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,
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY,
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());
Faculty faculty = ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get());
Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, venue, module, tagList);
Person person = new Person(name, phone, email, faculty, venue, module, tagList);

return new AddCommand(person);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/staffconnect/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class CliSyntax {
public static final Prefix PREFIX_NAME = new Prefix("n/");
public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_FACULTY = new Prefix("f/");
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/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_FACULTY;
import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE;
import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME;
import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY,
PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG);

Index index;
Expand All @@ -44,7 +45,7 @@ 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,
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY,
PREFIX_VENUE, PREFIX_MODULE);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();
Expand All @@ -58,6 +59,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}
if (argMultimap.getValue(PREFIX_FACULTY).isPresent()) {
editPersonDescriptor.setFaculty(ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get()));
}
if (argMultimap.getValue(PREFIX_VENUE).isPresent()) {
editPersonDescriptor.setVenue(ParserUtil.parseVenue(argMultimap.getValue(PREFIX_VENUE).get()));
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/staffconnect/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import staffconnect.commons.util.StringUtil;
import staffconnect.logic.parser.exceptions.ParseException;
import staffconnect.model.person.Email;
import staffconnect.model.person.Faculty;
import staffconnect.model.person.Module;
import staffconnect.model.person.Name;
import staffconnect.model.person.Phone;
Expand Down Expand Up @@ -81,6 +82,21 @@ public static Email parseEmail(String email) throws ParseException {
return new Email(trimmedEmail);
}

/**
* Parses a {@code String faculty} into an {@code Faculty}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code faculty} is invalid.
*/
public static Faculty parseFaculty(String faculty) throws ParseException {
requireNonNull(faculty);
String trimmedFaculty = faculty.trim();
if (!Faculty.isValidFaculty(trimmedFaculty)) {
throw new ParseException(Faculty.MESSAGE_CONSTRAINTS);
}
return new Faculty(trimmedFaculty);
}

/**
* Parses a {@code String venue} into an {@code Venue}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/staffconnect/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Person {
private final Name name;
private final Phone phone;
private final Email email;
private final Faculty faculty;

// Data fields
private final Venue venue;
Expand All @@ -29,11 +30,12 @@ public class Person {
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Venue venue, Module module, Set<Tag> tags) {
requireAllNonNull(name, phone, email, venue, module, tags);
public Person(Name name, Phone phone, Email email, Faculty faculty, Venue venue, Module module, Set<Tag> tags) {
requireAllNonNull(name, phone, email, faculty, venue, module, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.faculty = faculty;
this.venue = venue;
this.module = module;
this.tags.addAll(tags);
Expand All @@ -51,6 +53,10 @@ public Email getEmail() {
return email;
}

public Faculty getFaculty() {
return faculty;
}

public Venue getVenue() {
return venue;
}
Expand Down Expand Up @@ -99,6 +105,7 @@ public boolean equals(Object other) {
return name.equals(otherPerson.name)
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& faculty.equals(otherPerson.faculty)
&& venue.equals(otherPerson.venue)
&& module.equals(otherPerson.module)
&& tags.equals(otherPerson.tags);
Expand All @@ -107,7 +114,7 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, venue, module, tags);
return Objects.hash(name, phone, email, faculty, venue, module, tags);
}

@Override
Expand All @@ -116,6 +123,7 @@ public String toString() {
.add("name", name)
.add("phone", phone)
.add("email", email)
.add("faculty", faculty)
.add("venue", venue)
.add("module", module)
.add("tags", tags)
Expand Down
39 changes: 26 additions & 13 deletions src/main/java/staffconnect/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import staffconnect.model.ReadOnlyStaffBook;
import staffconnect.model.StaffBook;
import staffconnect.model.person.Email;
import staffconnect.model.person.Faculty;
import staffconnect.model.person.Module;
import staffconnect.model.person.Name;
import staffconnect.model.person.Person;
Expand All @@ -19,25 +20,37 @@
*/
public class SampleDataUtil {
public static Person[] getSamplePersons() {
return new Person[] {
return new Person[]{
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Venue("Blk 30 Geylang Street 29, #06-40"), new Module("CS1101S"),
getTagSet("professor")),
new Faculty("Computing"),
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("[email protected]"),
new Venue("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new Module("CS1231S"),
getTagSet("tutor", "friends")),
new Faculty("Computing"),
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("[email protected]"),
new Venue("Blk 11 Ang Mo Kio Street 74, #11-04"), new Module("CS2030S"),
getTagSet("professor")),
new Faculty("Computing"),
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("[email protected]"),
new Venue("Blk 436 Serangoon Gardens Street 26, #16-43"), new Module("CS2040S"),
getTagSet("professor")),
new Faculty("Computing"),
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("[email protected]"),
new Venue("Blk 47 Tampines Street 20, #17-35"), new Module("CS2100"),
getTagSet("tutor")),
new Faculty("Computing"),
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("[email protected]"),
new Venue("Blk 45 Aljunied Street 85, #11-31"), new Module("CS2101"),
getTagSet("professor"))
new Faculty("Computing"),
new Venue("Blk 45 Aljunied Street 85, #11-31"),
new Module("CS2101"),
getTagSet("professor"))
};
}

Expand Down
Loading

0 comments on commit 4c0e50a

Please sign in to comment.