Skip to content

Commit

Permalink
Finish upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
icantshootfloorballs committed Oct 4, 2024
1 parent 9b4f39e commit 00fe168
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -99,9 +100,10 @@ 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());
Remark updatedRemark = personToEdit.getRemark(); // edit command does not allow editing remarks
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRemark, updatedTags);
}

@Override
Expand Down
38 changes: 32 additions & 6 deletions src/main/java/seedu/address/logic/commands/RemarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package seedu.address.logic.commands;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.person.Remark;

import java.util.List;

/**
* Changes the remark of an existing person in the address book.
*/
public class RemarkCommand extends Command {

public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s";

public static final String MESSAGE_ADD_REMARK_SUCCESS = "Added remark to Person: %1$s";
public static final String MESSAGE_DELETE_REMARK_SUCCESS = "Removed remark from Person: %1$s";

private final Index index;
private final Remark remark;
Expand All @@ -30,8 +36,21 @@ public RemarkCommand(Index index, Remark remark) {

@Override
public CommandResult execute(Model model) throws CommandException {
throw new CommandException(
String.format(MESSAGE_ARGUMENTS, index.getOneBased(), remark));
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = new Person(
personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(),
personToEdit.getAddress(), remark, personToEdit.getTags());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

return new CommandResult(generateSuccessMessage(editedPerson));
}

@Override
Expand Down Expand Up @@ -61,6 +80,13 @@ public boolean equals(Object other) {
+ "Example: " + COMMAND_WORD + " 1 "
+ "r/ Likes to swim.";

public static final String MESSAGE_NOT_IMPLEMENTED_YET =
"Remark command not implemented yet";
/**
* Generates a command execution success message based on whether
* the remark is added to or removed from
* {@code personToEdit}.
*/
private String generateSuccessMessage(Person personToEdit) {
String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS;
return String.format(message, Messages.format(personToEdit));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -43,9 +44,10 @@ public AddCommand parse(String args) throws ParseException {
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());
Remark remark = new Remark("");
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, remark, tagList);

return new AddCommand(person);
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ public class Person {

// Data fields
private final Address address;
private final Remark remark;
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, Remark remark, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.remark = remark;
this.tags.addAll(tags);
}

Expand All @@ -53,6 +55,10 @@ public Address getAddress() {
return address;
}

public Remark getRemark() {
return remark;
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
Expand Down Expand Up @@ -110,6 +116,7 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("remark", remark)
.add("tags", tags)
.toString();
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;

/**
* Contains utility methods for populating {@code AddressBook} with sample data.
*/
public class SampleDataUtil {

public static final Remark EMPTY_REMARK = new Remark("");

public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"),
new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK,
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_REMARK,
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), EMPTY_REMARK,
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), EMPTY_REMARK,
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"),
new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK,
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK,
getTagSet("colleagues"))
};
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -28,6 +29,7 @@ class JsonAdaptedPerson {
private final String phone;
private final String email;
private final String address;
private final String remark;
private final List<JsonAdaptedTag> tags = new ArrayList<>();

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

if (remark == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName()));
}
final Remark modelRemark = new Remark(remark);

final Set<Tag> modelTags = new HashSet<>(personTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelRemark, 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 @@ -39,6 +39,8 @@ public class PersonCard extends UiPart<Region> {
@FXML
private Label email;
@FXML
private Label remark;
@FXML
private FlowPane tags;

/**
Expand All @@ -52,6 +54,7 @@ public PersonCard(Person person, int displayedIndex) {
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);
remark.setText(person.getRemark().value);
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="remark" styleClass="cell_small_label" text="\$remark" />
</VBox>
</GridPane>
</HBox>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"phone": "94351253",
"email": "[email protected]",
"address": "123, Jurong West Ave 6, #08-111",
"remark": "",
"tags": [ "friends" ]
}, {
"name": "Alice Pauline",
"phone": "94351253",
"email": "[email protected]",
"address": "4th street"
"address": "4th street",
"remark": ""
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,49 @@
"phone" : "94351253",
"email" : "[email protected]",
"address" : "123, Jurong West Ave 6, #08-111",
"remark" : "",
"tags" : [ "friends" ]
}, {
"name" : "Benson Meier",
"phone" : "98765432",
"email" : "[email protected]",
"address" : "311, Clementi Ave 2, #02-25",
"remark" : "",
"tags" : [ "owesMoney", "friends" ]
}, {
"name" : "Carl Kurz",
"phone" : "95352563",
"email" : "[email protected]",
"address" : "wall street",
"remark" : "",
"tags" : [ ]
}, {
"name" : "Daniel Meier",
"phone" : "87652533",
"email" : "[email protected]",
"address" : "10th street",
"remark" : "",
"tags" : [ "friends" ]
}, {
"name" : "Elle Meyer",
"phone" : "9482224",
"email" : "[email protected]",
"address" : "michegan ave",
"remark" : "",
"tags" : [ ]
}, {
"name" : "Fiona Kunz",
"phone" : "9482427",
"email" : "[email protected]",
"address" : "little tokyo",
"remark" : "",
"tags" : [ ]
}, {
"name" : "George Best",
"phone" : "9482442",
"email" : "[email protected]",
"address" : "4th street",
"remark" : "",
"tags" : [ ]
} ]
}
15 changes: 14 additions & 1 deletion src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;
import seedu.address.model.util.SampleDataUtil;

Expand All @@ -20,11 +21,13 @@ public class PersonBuilder {
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_EMAIL = "[email protected]";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_REMARK = "";

private Name name;
private Phone phone;
private Email email;
private Address address;
private Remark remark;
private Set<Tag> tags;

/**
Expand All @@ -35,6 +38,7 @@ public PersonBuilder() {
phone = new Phone(DEFAULT_PHONE);
email = new Email(DEFAULT_EMAIL);
address = new Address(DEFAULT_ADDRESS);
remark = new Remark(DEFAULT_REMARK);
tags = new HashSet<>();
}

Expand All @@ -46,6 +50,7 @@ public PersonBuilder(Person personToCopy) {
phone = personToCopy.getPhone();
email = personToCopy.getEmail();
address = personToCopy.getAddress();
remark = personToCopy.getRemark();
tags = new HashSet<>(personToCopy.getTags());
}

Expand Down Expand Up @@ -89,8 +94,16 @@ public PersonBuilder withEmail(String email) {
return this;
}

/**
* Sets the {@code Remark} of the {@code Person} that we are building.
*/
public PersonBuilder withRemark(String remark) {
this.remark = new Remark(remark);
return this;
}

public Person build() {
return new Person(name, phone, email, address, tags);
return new Person(name, phone, email, address, remark, tags);
}

}

0 comments on commit 00fe168

Please sign in to comment.