Skip to content

Commit

Permalink
Merge pull request #49 from thisisaditya17/feature/add-skills
Browse files Browse the repository at this point in the history
Create a field in add command (Skill Sets)
  • Loading branch information
rithanisk authored Oct 11, 2024
2 parents a08a491 + 5fb84ef commit ad44516
Show file tree
Hide file tree
Showing 32 changed files with 429 additions and 105 deletions.
17 changes: 11 additions & 6 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SKILLS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -21,22 +23,25 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. \n"
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_SKILLS + "SKILLS "
+ PREFIX_STATUS + "STATUS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ PREFIX_NOTE + "NOTE "
+ PREFIX_TAG + "TAG...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_EMAIL + "example@example.com "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_STATUS + "Interview Scheduled "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_SKILLS + "Java, Python, C++ "
+ PREFIX_STATUS + "Interviewed "
+ PREFIX_NOTE + "Super confident "
+ PREFIX_TAG + "friends ";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SKILLS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
Expand All @@ -29,6 +30,7 @@
import seedu.address.model.person.Note;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Skills;
import seedu.address.model.person.Status;
import seedu.address.model.tag.Tag;

Expand All @@ -47,12 +49,17 @@ public class EditCommand extends Command {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_SKILLS + "SKILLS] "
+ "[" + PREFIX_STATUS + "STATUS]"
+ "[" + PREFIX_NOTE + "NOTE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
+ PREFIX_EMAIL + "[email protected]"
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_SKILLS + "java, python "
+ PREFIX_TAG + "friends";


public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand Down Expand Up @@ -105,11 +112,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Skills updatedSkills = editPersonDescriptor.getSkills().orElse(personToEdit.getSkills());
Status updatedStatus = editPersonDescriptor.getStatus().orElse(personToEdit.getStatus());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Note updatedNote = editPersonDescriptor.getNote().orElse(personToEdit.getNote());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedSkills,
updatedStatus, updatedNote, updatedTags);
}

Expand Down Expand Up @@ -146,6 +154,7 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private Skills skills;
private Status status;
private Note note;
private Set<Tag> tags;
Expand All @@ -161,6 +170,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
setSkills(toCopy.skills);
setStatus(toCopy.status);
setNote(toCopy.note);
setTags(toCopy.tags);
Expand Down Expand Up @@ -205,6 +215,14 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setSkills(Skills skills) {
this.skills = skills;
}

public Optional<Skills> getSkills() {
return Optional.ofNullable(skills);
}

public void setStatus(Status status) {
this.status = status;
}
Expand Down Expand Up @@ -254,6 +272,7 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(skills, otherEditPersonDescriptor.skills)
&& Objects.equals(status, otherEditPersonDescriptor.status)
&& Objects.equals(note, otherEditPersonDescriptor.note)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
Expand All @@ -266,6 +285,7 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("skills", tags)
.add("status", status)
.add("note", note)
.add("tags", tags)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/NoteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit.getPhone(),
personToEdit.getEmail(),
personToEdit.getAddress(),
personToEdit.getSkills(),
personToEdit.getStatus(), // Add this line to get the status
note,
personToEdit.getNote(),
personToEdit.getTags()
);

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SKILLS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -20,6 +21,7 @@
import seedu.address.model.person.Note;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Skills;
import seedu.address.model.person.Status;
import seedu.address.model.tag.Tag;

Expand All @@ -36,21 +38,23 @@ 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_ADDRESS,
PREFIX_SKILLS,
PREFIX_STATUS, PREFIX_NOTE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_STATUS, PREFIX_NOTE)
PREFIX_SKILLS, PREFIX_STATUS, PREFIX_NOTE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_STATUS, PREFIX_NOTE);
PREFIX_SKILLS, PREFIX_STATUS, PREFIX_NOTE);

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());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Skills skills = ParserUtil.parseSkills(argMultimap.getValue(PREFIX_SKILLS).get());
Status status = ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get());

// Check if note is present and parse it accordingly
Expand All @@ -62,9 +66,7 @@ public AddCommand parse(String args) throws ParseException {
}

Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, status, note, tagList);

Person person = new Person(name, phone, email, address, skills, status, note, tagList);
return new AddCommand(person);
}

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,6 +12,7 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_NOTE = new Prefix("note/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_SKILLS = new Prefix("s/");
public static final Prefix PREFIX_STATUS = new Prefix("st/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SKILLS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand Down Expand Up @@ -36,7 +37,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_STATUS, PREFIX_NOTE, PREFIX_TAG);
PREFIX_SKILLS, PREFIX_STATUS, PREFIX_NOTE, PREFIX_TAG);

Index index;

Expand All @@ -47,7 +48,7 @@ public EditCommand parse(String args) throws ParseException {
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_STATUS, PREFIX_NOTE );
PREFIX_SKILLS, PREFIX_STATUS, PREFIX_NOTE);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand All @@ -64,6 +65,9 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}

if (argMultimap.getValue(PREFIX_SKILLS).isPresent()) {
editPersonDescriptor.setSkills(ParserUtil.parseSkills(argMultimap.getValue(PREFIX_SKILLS).get()));
}
if (argMultimap.getValue(PREFIX_STATUS).isPresent()) {
editPersonDescriptor.setStatus(ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get()));
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Note;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Skills;
import seedu.address.model.person.Status;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -153,4 +154,19 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}
return tagSet;
}

/**
* Parses a {@code String skills} into a {@code Skills}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code skills} is invalid.
*/
public static Skills parseSkills(String skills) throws ParseException {
requireNonNull(skills);
String trimmedSkills = skills.trim();
if (!Skills.isValidSkillsString(trimmedSkills)) {
throw new ParseException(Skills.MESSAGE_CONSTRAINTS);
}
return new Skills(trimmedSkills);
}
}
16 changes: 12 additions & 4 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ public class Person {

// Data fields
private final Address address;
private final Skills skills;

private final Status status;
private final Note note;
private final Set<Tag> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Status status,
Note note, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, status, note, tags);
public Person(Name name, Phone phone, Email email, Address address, Skills skills,
Status status, Note note, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, skills, status, note, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.skills = skills; // From feature/add-skills
this.status = status; // From feature/add-application-status
this.note = note; // New feature (Week 8)
this.tags.addAll(tags);
Expand All @@ -58,6 +61,9 @@ public Address getAddress() {
return address;
}

public Skills getSkills() {
return skills;
}
public Status getStatus() {
return status;
}
Expand Down Expand Up @@ -107,6 +113,7 @@ public boolean equals(Object other) {
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& skills.equals(otherPerson.skills)
&& status.equals(otherPerson.status)
&& note.equals(otherPerson.note)
&& tags.equals(otherPerson.tags);
Expand All @@ -115,7 +122,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, address, status, note, tags);
return Objects.hash(name, phone, email, address, skills, status, note, tags);
}

@Override
Expand All @@ -125,6 +132,7 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("skills", skills)
.add("status", status)
.add("note", note)
.add("tags", tags)
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/seedu/address/model/person/Skills.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's skills in the TalentSG
* Guarantees: immutable; is valid as declared in {@link #isValidSkillsString(String)}
*/
public class Skills {

public static final String MESSAGE_CONSTRAINTS =
"Skills should be a non-empty string consisting of alphabetic characters, separated by commas. "
+ "Each skill should be between 1 and 30 characters long";
public static final String VALIDATION_REGEX = "^[a-zA-Z0-9+]+(, [a-zA-Z0-9+]+)*$";
public final String value;

/**
* Constructs a {@code Skills}.
*
* @param skills A valid skills string.
*/
public Skills(String skills) {
requireNonNull(skills);
checkArgument(isValidSkillsString(skills), MESSAGE_CONSTRAINTS);
value = skills;
}

/**
* Returns true if a given string is a valid skill input.
*/
public static boolean isValidSkillsString(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof Skills)) {
return false;
}

Skills otherSkills = (Skills) other;
return value.equals(otherSkills.value);
}

@Override
public int hashCode() {
return value.hashCode();
}

}
Loading

0 comments on commit ad44516

Please sign in to comment.