Skip to content

Commit

Permalink
Merge pull request #55 from ForAeons/reduce-addstu-compulsory-field
Browse files Browse the repository at this point in the history
Reduce compulsory field for the addstu command
  • Loading branch information
wxiaoyun authored Mar 18, 2024
2 parents 0f8b286 + ebe59fa commit b453b66
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 22 deletions.
9 changes: 7 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,19 @@ Adds a student to the address book.

Format: `addstu n/NAME p/PHONE_NUMBER e/EMAIL nn/NUSNET_ID a/ADDRESS [t/TAG]…​`

* Add a student with the given details.
* The name and nusnet id must be provided. And nusnet id must be unique.
* All the remaining fields are optional. If not provided, a placeholder value will be used.

<box type="tip" seamless>

**Tip:** A person can have any number of tags (including 0)
</box>

Examples:
* `addstu n/John Doe p/98765432 e/johnd@example.com nn/e1234567 a/John street, block 123, #01-01`
* `add n/Betsy nn/e01234567 Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal`
* `addstu n/John Doe nn/e1234567 [p/98765432] [e/johnd@example.com] [a/John street, block 123, #01-01]`
* `addstu n/Betsy Crowe nn/e01234567 t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal`
* `addstu n/Betsy Crowe nn/e01234567`

### Listing all students : `list`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class AddPersonCommand extends Command {
COMMAND_WORD,
"Adds a person to the address book. ",
PARAMETER_NAME,
PARAMETER_PHONE,
PARAMETER_EMAIL,
PARAMETER_NUSNET,
PARAMETER_ADDRESS,
PARAMETER_PHONE.asOptional(true),
PARAMETER_EMAIL.asOptional(true),
PARAMETER_ADDRESS.asOptional(true),
PARAMETER_TAG.asMultiple(2)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,42 @@ public class AddPersonCommandParser implements Parser<AddPersonCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public AddPersonCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_NUSNET,
PREFIX_ADDRESS, PREFIX_TAG);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(
args,
PREFIX_NAME,
PREFIX_PHONE,
PREFIX_EMAIL,
PREFIX_NUSNET,
PREFIX_ADDRESS,
PREFIX_TAG
);

if (!ArgumentMultimap.arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_NUSNET)
|| !argMultimap.getPreamble().isEmpty()) {
if (!ArgumentMultimap.arePrefixesPresent(
argMultimap,
PREFIX_NAME,
PREFIX_NUSNET
) || !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddPersonCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_NUSNET, PREFIX_ADDRESS);
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());
NusNet nusNet = ParserUtil.parseNusNet(argMultimap.getValue(PREFIX_NUSNET).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
argMultimap.verifyNoDuplicatePrefixesFor(
PREFIX_NAME,
PREFIX_PHONE,
PREFIX_EMAIL,
PREFIX_NUSNET,
PREFIX_ADDRESS
);

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME)
.get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE)
.orElseGet(() -> Phone.PLACEHOLDER));
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL)
.orElseGet(() -> Email.PLACEHOLDER));
NusNet nusNet = ParserUtil.parseNusNet(argMultimap.getValue(PREFIX_NUSNET)
.get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS)
.orElseGet(() -> Address.PLACEHOLDER));
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, nusNet, address, tagList);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
public class Address {

public static final String PLACEHOLDER = "Address not provided";
public static final String MESSAGE_CONSTRAINTS = "Addresses can take any values, and it should not be blank";

/*
Expand All @@ -34,6 +35,9 @@ public Address(String address) {
* Returns true if a given string is a valid email.
*/
public static boolean isValidAddress(String test) {
if (test.equals(PLACEHOLDER)) {
return true;
}
return test.matches(VALIDATION_REGEX);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
public class Email {

public static final String PLACEHOLDER = "Email not provided";
private static final String SPECIAL_CHARACTERS = "+_.-";
public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain "
+ "and adhere to the following constraints:\n"
Expand Down Expand Up @@ -48,6 +49,10 @@ public Email(String email) {
* Returns if a given string is a valid email.
*/
public static boolean isValidEmail(String test) {
if (test.equals(PLACEHOLDER)) {
return true;
}

return test.matches(VALIDATION_REGEX);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Person {
*/
public Person(Name name, Phone phone, Email email, NusNet nusNet,
Address address, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, attendance, tags);
requireAllNonNull(name, nusNet, attendance, tags);
this.name = name;
this.phone = phone;
this.email = email;
Expand All @@ -47,7 +47,7 @@ public Person(Name name, Phone phone, Email email, NusNet nusNet,
*/
public Person(Name name, Phone phone, Email email, NusNet nusNet,
Address address, Set<WeekNumber> attendance, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, attendance, tags);
requireAllNonNull(name, nusNet, attendance, tags);
this.name = name;
this.phone = phone;
this.email = email;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class Phone {


public static final String PLACEHOLDER = "Phone number not provided";
public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";
Expand All @@ -30,6 +31,10 @@ public Phone(String phone) {
* Returns true if a given string is a valid phone number.
*/
public static boolean isValidPhone(String test) {
if (test.equals(PLACEHOLDER)) {
return true;
}

return test.matches(VALIDATION_REGEX);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
<Label fx:id="name" text="\$first" styleClass="cell_big_label" />
</HBox>
<FlowPane fx:id="tags" />
<Label fx:id="nusNet" styleClass="cell_small_label" text="\$nusNet" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="nusNet" styleClass="cell_small_label" text="\$nusNet" />
<FlowPane fx:id="attendance" styleClass="container" />
</VBox>
</GridPane>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo";
public static final String VALID_NAME_CHAD = "Chad Giga";
public static final String VALID_PHONE_AMY = "11111111";
public static final String VALID_PHONE_BOB = "22222222";
public static final String VALID_EMAIL_AMY = "amy@example.com";
public static final String VALID_EMAIL_BOB = "bob@example.com";
public static final String VALID_NUSNET_AMY = "e1111111";
public static final String VALID_NUSNET_BOB = "e2222222";
public static final String VALID_NUSNET_CHAD = "e3333333";
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1";
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
public static final String VALID_WEEK_NUMBER_1 = "1";
Expand All @@ -45,12 +47,14 @@ public class CommandTestUtil {

public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
public static final String NAME_DESC_CHAD = " " + PREFIX_NAME + VALID_NAME_CHAD;
public static final String PHONE_DESC_AMY = " " + PREFIX_PHONE + VALID_PHONE_AMY;
public static final String PHONE_DESC_BOB = " " + PREFIX_PHONE + VALID_PHONE_BOB;
public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY;
public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB;
public static final String NUSNET_DESC_AMY = " " + PREFIX_NUSNET + VALID_NUSNET_AMY;
public static final String NUSNET_DESC_BOB = " " + PREFIX_NUSNET + VALID_NUSNET_BOB;
public static final String NUSNET_DESC_CHAD = " " + PREFIX_NUSNET + VALID_NUSNET_CHAD;
public static final String ADDRESS_DESC_AMY = " " + PREFIX_ADDRESS + VALID_ADDRESS_AMY;
public static final String ADDRESS_DESC_BOB = " " + PREFIX_ADDRESS + VALID_ADDRESS_BOB;
public static final String WEEK_NUMBER_DESC_1 = " " + PREFIX_WEEK + VALID_WEEK_NUMBER_1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.parser;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB;
Expand All @@ -13,8 +14,10 @@
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_CHAD;
import static seedu.address.logic.commands.CommandTestUtil.NUSNET_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NUSNET_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.NUSNET_DESC_CHAD;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY;
Expand Down Expand Up @@ -157,6 +160,9 @@ public void parse_optionalFieldsMissing_success() {
assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY
+ NUSNET_DESC_AMY + ADDRESS_DESC_AMY,
new AddPersonCommand(expectedPerson2));

// only name and nusnet provided
assertDoesNotThrow(() -> parser.parse(NAME_DESC_CHAD + NUSNET_DESC_CHAD));
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/seedu/address/model/person/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public void isValidAddress() {
assertTrue(Address.isValidAddress("Blk 456, Den Road, #01-355"));
assertTrue(Address.isValidAddress("-")); // one character
assertTrue(Address.isValidAddress("Leng Inc; 1234 Market St; San Francisco CA 2349879; USA")); // long address

// placeholder
assertTrue(Address.isValidAddress(Address.PLACEHOLDER));
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/seedu/address/model/person/EmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public void isValidEmail() {
assertTrue(Email.isValidEmail("peter_jack@very-very-very-long-example.com")); // long domain name
assertTrue(Email.isValidEmail("if.you.dream.it_you.can.do.it@example.com")); // long local part
assertTrue(Email.isValidEmail("e1234567@u.nus.edu")); // more than one period in domain

// placeholder
assertTrue(Email.isValidEmail(Email.PLACEHOLDER));
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/seedu/address/model/person/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void isValidPhone() {
assertTrue(Phone.isValidPhone("911")); // exactly 3 numbers
assertTrue(Phone.isValidPhone("93121534"));
assertTrue(Phone.isValidPhone("124293842033123")); // long phone numbers

// placeholder
assertTrue(Phone.isValidPhone(Phone.PLACEHOLDER));
}

@Test
Expand Down

0 comments on commit b453b66

Please sign in to comment.