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

Create a field in add command (Skill Sets) #49

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a7d9494
Update AddCommand.java to have a skills field
thisisaditya17 Oct 8, 2024
f90e16e
Create Skills.java
thisisaditya17 Oct 8, 2024
f909a69
Update AddCommandParser.java to incorporate skills field
thisisaditya17 Oct 8, 2024
bdb0ead
Update CliSyntax.java with new prefix for skills
thisisaditya17 Oct 8, 2024
7165c37
Update EditCommand.java to edit skills field as well
thisisaditya17 Oct 8, 2024
305492f
Update EditCommandParser.java to incorporate skills field
thisisaditya17 Oct 8, 2024
9811d15
Update ParserUtil.java to add parseSkills method
thisisaditya17 Oct 8, 2024
d5d50f3
Update Person.java
thisisaditya17 Oct 8, 2024
1d5b80b
Update test cases
thisisaditya17 Oct 8, 2024
1dd2af0
Update PersonCard.java to include skills label
thisisaditya17 Oct 8, 2024
c3c9f65
Update PersonBuilder.java
thisisaditya17 Oct 8, 2024
41a207e
Update PersonListCard.fxml to add skills label
thisisaditya17 Oct 8, 2024
b1df8f8
Fix all the styling errors
thisisaditya17 Oct 9, 2024
630c26c
Fix styling error for tests
thisisaditya17 Oct 9, 2024
209f063
Disable test cases temporarily
thisisaditya17 Oct 9, 2024
e5c9cf4
Fix all the test cases to run the tests
thisisaditya17 Oct 9, 2024
56beb08
Add some extra test cases
thisisaditya17 Oct 9, 2024
c3dc13c
Fix all the changed test cases
thisisaditya17 Oct 10, 2024
93aaa38
Create SkillsTest class for Skills.java
thisisaditya17 Oct 10, 2024
9bb2a02
Merge branch 'master' into feature/add-skills
thisisaditya17 Oct 10, 2024
fdf0a7a
Update the test cases with new changes
thisisaditya17 Oct 11, 2024
8d942a9
Fix test bugs in NoteCommandTest.java
thisisaditya17 Oct 11, 2024
1f61808
Add example in the Add command message
thisisaditya17 Oct 11, 2024
89810ad
Fix the checkStyle error for Add Command
thisisaditya17 Oct 11, 2024
5fb84ef
Fix the skills test case bug
thisisaditya17 Oct 11, 2024
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
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imports are in lexicographical order! good!

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 @@

// 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 @@
return address;
}

public Skills getSkills() {
return skills;
}
public Status getStatus() {
return status;
}
Expand Down Expand Up @@ -107,6 +113,7 @@
&& 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 @@
@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);

Check warning on line 125 in src/main/java/seedu/address/model/person/Person.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/person/Person.java#L125

Added line #L125 was not covered by tests
}

@Override
Expand All @@ -125,6 +132,7 @@
.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