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

Add Postal Code #55

Merged
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static String format(Person person) {
.append(person.getEmail())
.append("; Address: ")
.append(person.getAddress())
.append("; Postal Code: ")
.append(person.getPostalCode())
.append("; Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_POSTALCODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -26,12 +27,14 @@ public class AddCommand extends Command {
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_POSTALCODE + "POSTAL CODE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_POSTALCODE + "578578 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class EditCommand extends Command {
private final EditPersonDescriptor editPersonDescriptor;

/**
* @param index of the person in the filtered person list to edit
* @param index of the person in the filtered person list to edit
Copy link
Collaborator

@felixchanyy felixchanyy Mar 15, 2024

Choose a reason for hiding this comment

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

Should the extra space be removed?

* @param editPersonDescriptor details to edit the person with
*/
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
Expand Down Expand Up @@ -101,7 +101,8 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
personToEdit.getPostalCode(), updatedTags);

Choose a reason for hiding this comment

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

personToEdit.getPostalCode() this would return the original postal code instead of the new value.

But isn't this edit command? 😅😅 I don't think you have to touch this.

Copy link
Author

Choose a reason for hiding this comment

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

Yeap, I set it to be like this because I have not officially change the edit function yet for postal code. I think if I did not make any changes to the edit, the test cases for the edit will not pass, and hence the build will not go through at the GitHub. The current edit implementation is just temporary, I will edit this when I doing the next iteration. But yes, thanks for noticing and bringing it up :)

}

@Override
Expand Down Expand Up @@ -139,7 +140,8 @@ public static class EditPersonDescriptor {
private Address address;
private Set<Tag> tags;

public EditPersonDescriptor() {}
public EditPersonDescriptor() {
}

/**
* Copy constructor.
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
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_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_POSTALCODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.house.PostalCode;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -31,21 +33,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_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_POSTALCODE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_POSTALCODE)
|| !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);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_POSTALCODE);
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());
PostalCode postalCode = ParserUtil.parsePostalCode(argMultimap.getValue(PREFIX_POSTALCODE).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, tagList);
Person person = new Person(name, phone, email, address, postalCode, 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 @@ -11,5 +11,6 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_POSTALCODE = new Prefix("postal/");
Copy link
Collaborator

@felixchanyy felixchanyy Mar 16, 2024

Choose a reason for hiding this comment

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

Perhaps using 'pc/' instead of 'postal/' would allow users to type faster?


}
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.house.PostalCode;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -25,6 +26,7 @@ public class ParserUtil {
/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
*
* @throws ParseException if the specified index is invalid (not non-zero unsigned integer).
*/
public static Index parseIndex(String oneBasedIndex) throws ParseException {
Expand Down Expand Up @@ -121,4 +123,19 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}
return tagSet;
}

/**
* Parses a {@code String postalCode} into a {@code postalCode}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code postalCode} is invalid.
*/
public static PostalCode parsePostalCode(String postalCode) throws ParseException {
requireNonNull(postalCode);
String trimmedPostalCode = postalCode.trim();
if (!PostalCode.isValidPostalCode(trimmedPostalCode)) {
throw new ParseException(PostalCode.MESSAGE_CONSTRAINTS);
}
return new PostalCode(trimmedPostalCode);
}
}
59 changes: 59 additions & 0 deletions src/main/java/seedu/address/model/house/PostalCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package seedu.address.model.house;

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

/**
* Represents a House's postal code in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidPostalCode(String)}
*/
public class PostalCode {

public static final String MESSAGE_CONSTRAINTS =
"The postal code should only contain numbers, and it should be only 6 digits long";
public static final String VALIDATION_REGEX = "\\d{6}";
public final String value;

/**
* Constructs a {@code PostalCode}.
*
* @param postalCode A valid postal code.
*/
public PostalCode(String postalCode) {
requireNonNull(postalCode);
checkArgument(isValidPostalCode(postalCode), MESSAGE_CONSTRAINTS);
value = postalCode;
}

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

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

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

if (!(other instanceof PostalCode)) {
return false;
}

PostalCode otherPostalCode = (PostalCode) other;
return value.equals(otherPostalCode.value);
}

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

Check warning on line 56 in src/main/java/seedu/address/model/house/PostalCode.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/house/PostalCode.java#L56

Added line #L56 was not covered by tests
}

}
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.house.PostalCode;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -23,17 +24,19 @@

// Data fields
private final Address address;
private final PostalCode postalCode;
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, Set<Tag> tags) {
public Person(Name name, Phone phone, Email email, Address address, PostalCode postalCode, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.postalCode = postalCode;
this.tags.addAll(tags);
}

Expand All @@ -53,6 +56,10 @@
return address;
}

public PostalCode getPostalCode() {
return postalCode;
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
Expand Down Expand Up @@ -94,13 +101,14 @@
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& postalCode.equals(otherPerson.postalCode)
&& 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, address, tags);
return Objects.hash(name, phone, email, address, postalCode, tags);

Check warning on line 111 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#L111

Added line #L111 was not covered by tests
}

@Override
Expand All @@ -110,6 +118,7 @@
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("postal code", postalCode)
.add("tags", tags)
.toString();
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.house.PostalCode;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -20,22 +21,22 @@ 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 Address("Blk 30 Geylang Street 29, #06-40"),
new Address("Blk 30 Geylang Street 29, #06-40"), new PostalCode("123456"),
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new PostalCode("123567"),
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new PostalCode("123890"),
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new PostalCode("123123"),
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
new Address("Blk 47 Tampines Street 20, #17-35"), new PostalCode("123010"),
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
new Address("Blk 45 Aljunied Street 85, #11-31"), new PostalCode("123787"),
getTagSet("colleagues"))
};
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.house.PostalCode;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -28,6 +29,7 @@ class JsonAdaptedPerson {
private final String phone;
private final String email;
private final String address;
private final String postalCode;
private final List<JsonAdaptedTag> tags = new ArrayList<>();

/**
Expand All @@ -36,11 +38,13 @@ class JsonAdaptedPerson {
@JsonCreator
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("postalCode") String postalCode,
@JsonProperty("tags") List<JsonAdaptedTag> tags) {
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.postalCode = postalCode;
if (tags != null) {
this.tags.addAll(tags);
}
Expand All @@ -54,6 +58,7 @@ public JsonAdaptedPerson(Person source) {
phone = source.getPhone().value;
email = source.getEmail().value;
address = source.getAddress().value;
postalCode = source.getPostalCode().value;
tags.addAll(source.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList()));
Expand Down Expand Up @@ -102,8 +107,17 @@ public Person toModelType() throws IllegalValueException {
}
final Address modelAddress = new Address(address);

if (postalCode == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
PostalCode.class.getSimpleName()));
}
if (!PostalCode.isValidPostalCode(postalCode)) {
throw new IllegalValueException(PostalCode.MESSAGE_CONSTRAINTS);
}
final PostalCode modelPostalCode = new PostalCode(postalCode);

final Set<Tag> modelTags = new HashSet<>(personTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelPostalCode, modelTags);
}

}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
private Label email;
@FXML
private FlowPane tags;
@FXML
private Label postalCode;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
Expand All @@ -52,6 +54,7 @@
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);
postalCode.setText("S" + person.getPostalCode().value);

Check warning on line 57 in src/main/java/seedu/address/ui/PersonCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonCard.java#L57

Added line #L57 was not covered by tests
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<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="postalCode" styleClass="cell_small_label" text="\$postalCode" />
</VBox>
</GridPane>
</HBox>
Loading
Loading