Skip to content

Commit

Permalink
Merge f08022c into 2a956aa
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonggiee committed Mar 17, 2020
2 parents 2a956aa + f08022c commit f8ea76d
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HEIGHT;
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_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TARGET_WEIGHT;

Expand All @@ -34,7 +35,8 @@ public class AddCommand extends Command {
+ "[" + PREFIX_GENDER + "GENDER] "
+ "[" + PREFIX_CURRENT_WEIGHT + "CURRENT_WEIGHT] "
+ "[" + PREFIX_TARGET_WEIGHT + "TARGET_WEIGHT] "
+ "[" + PREFIX_HEIGHT + "HEIGHT]\n"
+ "[" + PREFIX_HEIGHT + "HEIGHT] "
+ "[" + PREFIX_REMARK + "REMARK]\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
Expand All @@ -45,8 +47,9 @@ public class AddCommand extends Command {
+ PREFIX_GENDER + "Male "
+ PREFIX_BIRTHDAY + "26-01-1980 "
+ PREFIX_CURRENT_WEIGHT + "96 "
+ PREFIX_TARGET_WEIGHT + "69"
+ PREFIX_HEIGHT + "156";
+ PREFIX_TARGET_WEIGHT + "69 "
+ PREFIX_HEIGHT + "156 "
+ PREFIX_REMARK + "need to do more pushups";

public static final String MESSAGE_SUCCESS = "New client added: %1$s";
public static final String MESSAGE_DUPLICATE_CLIENT = "This client already exists in the address book";
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HEIGHT;
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_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TARGET_WEIGHT;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CLIENTS;
Expand All @@ -33,6 +34,7 @@
import seedu.address.model.client.Height;
import seedu.address.model.client.Name;
import seedu.address.model.client.Phone;
import seedu.address.model.client.Remark;
import seedu.address.model.client.TargetWeight;
import seedu.address.model.tag.Tag;

Expand All @@ -56,7 +58,8 @@ public class EditCommand extends Command {
+ "[" + PREFIX_BIRTHDAY + "BIRTHDAY] "
+ "[" + PREFIX_CURRENT_WEIGHT + "CURRENT_WEIGHT] "
+ "[" + PREFIX_TARGET_WEIGHT + "TARGET_WEIGHT] "
+ "[" + PREFIX_HEIGHT + "HEIGHT]\n"
+ "[" + PREFIX_HEIGHT + "HEIGHT] "
+ "[" + PREFIX_REMARK + "REMARK]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "johndoe@example.com "
Expand Down Expand Up @@ -101,9 +104,11 @@ private static Client createEditedClient(Client clientToEdit, EditClientDescript
.orElse(clientToEdit.getCurrentWeight());
TargetWeight updatedTargetWeight = editClientDescriptor.getTargetWeight()
.orElse(clientToEdit.getTargetWeight());
Remark updatedRemark = editClientDescriptor.getRemark()
.orElse(clientToEdit.getRemark());

return new Client(updatedName, updatedGender, updatedPhone, updatedEmail, updatedAddress, updatedTags,
updatedBirthday, updatedCurrentWeight, updatedTargetWeight, updatedHeight);
updatedBirthday, updatedCurrentWeight, updatedTargetWeight, updatedHeight, updatedRemark);
}

@Override
Expand Down Expand Up @@ -159,6 +164,7 @@ public static class EditClientDescriptor {
private Height height;
private CurrentWeight currentWeight;
private TargetWeight targetWeight;
private Remark remark;

public EditClientDescriptor() {
}
Expand All @@ -177,14 +183,15 @@ public EditClientDescriptor(EditClientDescriptor toCopy) {
setHeight(toCopy.height);
setCurrentWeight(toCopy.currentWeight);
setTargetWeight(toCopy.targetWeight);
setRemark(toCopy.remark);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, gender, phone, email, address, tags, birthday,
currentWeight, targetWeight, height);
currentWeight, targetWeight, height, remark);
}

public Optional<Name> getName() {
Expand Down Expand Up @@ -259,6 +266,14 @@ public void setTargetWeight(TargetWeight targetWeight) {
this.targetWeight = targetWeight;
}

public Optional<Remark> getRemark() {
return Optional.ofNullable(remark);
}

public void setRemark(Remark remark) {
this.remark = remark;
}

/**
* Returns an unmodifiable tag set, which throws
* {@code UnsupportedOperationException} if modification is attempted. Returns
Expand Down Expand Up @@ -300,7 +315,8 @@ && getTags().equals(e.getTags())
&& getBirthday().equals(e.getBirthday())
&& getHeight().equals(e.getHeight())
&& getCurrentWeight().equals(e.getCurrentWeight())
&& getTargetWeight().equals(e.getTargetWeight());
&& getTargetWeight().equals(e.getTargetWeight())
&& getRemark().equals(e.getRemark());
}
}
}
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HEIGHT;
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_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TARGET_WEIGHT;

Expand All @@ -27,6 +28,7 @@
import seedu.address.model.client.Height;
import seedu.address.model.client.Name;
import seedu.address.model.client.Phone;
import seedu.address.model.client.Remark;
import seedu.address.model.client.TargetWeight;
import seedu.address.model.tag.Tag;

Expand All @@ -45,7 +47,7 @@ public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME,
PREFIX_GENDER, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_TAG, PREFIX_BIRTHDAY, PREFIX_CURRENT_WEIGHT, PREFIX_TARGET_WEIGHT,
PREFIX_HEIGHT);
PREFIX_HEIGHT, PREFIX_REMARK);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME,
PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
Expand Down Expand Up @@ -78,9 +80,13 @@ public AddCommand parse(String args) throws ParseException {
TargetWeight targetWeight = targetWeightString.isPresent()
? ParserUtil.parseTargetWeight(targetWeightString.get())
: new TargetWeight("");
Optional<String> remarkString = argMultimap.getValue(PREFIX_REMARK);
Remark remark = remarkString.isPresent()
? ParserUtil.parseRemark(remarkString.get())
: new Remark("");

Client client = new Client(name, gender, phone, email, address, tagList, birthday,
currentWeight, targetWeight, height);
currentWeight, targetWeight, height, remark);

return new AddCommand(client);
}
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 @@ -10,6 +10,7 @@ public class CliSyntax {
public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");
public static final Prefix PREFIX_GENDER = new Prefix("g/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_BIRTHDAY = new Prefix("b/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HEIGHT;
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_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TARGET_WEIGHT;

Expand Down Expand Up @@ -40,7 +41,7 @@ public EditCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_GENDER, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_TAG, PREFIX_BIRTHDAY, PREFIX_CURRENT_WEIGHT, PREFIX_TARGET_WEIGHT,
PREFIX_HEIGHT);
PREFIX_HEIGHT, PREFIX_REMARK);

Index index;

Expand Down Expand Up @@ -80,6 +81,9 @@ public EditCommand parse(String args) throws ParseException {
editClientDescriptor.setTargetWeight(ParserUtil.parseTargetWeight(argMultimap
.getValue(PREFIX_TARGET_WEIGHT).get()));
}
if (argMultimap.getValue(PREFIX_REMARK).isPresent()) {
editClientDescriptor.setRemark(ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get()));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editClientDescriptor::setTags);

if (!editClientDescriptor.isAnyFieldEdited()) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.model.client.Height;
import seedu.address.model.client.Name;
import seedu.address.model.client.Phone;
import seedu.address.model.client.Remark;
import seedu.address.model.client.TargetWeight;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -101,6 +102,18 @@ public static Email parseEmail(String email) throws ParseException {
return new Email(trimmedEmail);
}

/**
* Parses a {@code String remark} into an {@code Remark}. Leading and trailing
* whitespaces will be trimmed.
*
* @throws ParseException if the given {@code remark} is invalid.
*/
public static Remark parseRemark(String remark) throws ParseException {
requireNonNull(remark);
String trimmedRemark = remark.trim();
return new Remark(trimmedRemark);
}

/**
* Parses a {@code String gender} into an {@code Gender}.
*
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/model/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ public class Client {
private Gender gender;
private TargetWeight targetWeight;
private Height height;
private Remark remark;

// TODO: remove this overloaded constructor after finalising attributes
/**
* Overloaded Client constructor for FitBiz.
*/
public Client(Name name, Gender gender, Phone phone, Email email, Address address, Set<Tag> tags, Birthday birthday,
CurrentWeight currentWeight, TargetWeight targetWeight, Height height) {
CurrentWeight currentWeight, TargetWeight targetWeight, Height height, Remark remark) {
requireAllNonNull(name, phone, email, address, tags, birthday);
this.name = name;
this.gender = gender;
Expand All @@ -49,6 +50,7 @@ public Client(Name name, Gender gender, Phone phone, Email email, Address addres
this.currentWeight = currentWeight;
this.targetWeight = targetWeight;
this.height = height;
this.remark = remark;
}

/**
Expand Down Expand Up @@ -93,6 +95,10 @@ public Address getAddress() {
return address;
}

public Remark getRemark() {
return remark;
}

public Birthday getBirthday() {
return birthday;
}
Expand Down Expand Up @@ -162,7 +168,8 @@ 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, gender, phone, email, address, tags, birthday, currentWeight, targetWeight, height);
return Objects.hash(name, gender, phone, email, address, tags, birthday,
currentWeight, targetWeight, height, remark);
}

@Override
Expand All @@ -185,6 +192,8 @@ public String toString() {
.append(getTargetWeight())
.append(" Height: ")
.append(getHeight())
.append(" Remark: ")
.append(getRemark())
.append(" Tags: ");
getTags().forEach(builder::append);
return builder.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 @@ -15,6 +15,7 @@
import seedu.address.model.client.Height;
import seedu.address.model.client.Name;
import seedu.address.model.client.Phone;
import seedu.address.model.client.Remark;
import seedu.address.model.client.TargetWeight;
import seedu.address.model.tag.Tag;

Expand All @@ -27,32 +28,32 @@ public static Client[] getSampleClients() {
new Client(new Name("Alex Yeoh"), new Gender("Male"), new Phone("87438807"),
new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends"), new Birthday(""), new CurrentWeight(""), new TargetWeight(""),
new Height("")),
new Height(""), new Remark("")),
new Client(new Name("Bernice Yu"), new Gender("Female"), new Phone("99272758"),
new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends"), new Birthday(""), new CurrentWeight(""), new TargetWeight(""),
new Height("")),
new Height(""), new Remark("")),
new Client(new Name("Charlotte Oliveiro"), new Gender("Female"), new Phone("93210283"),
new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours"), new Birthday(""), new CurrentWeight(""), new TargetWeight(""),
new Height("")),
new Height(""), new Remark("")),
new Client(new Name("David Li"), new Gender("Male"), new Phone("91031282"),
new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family"), new Birthday(""), new CurrentWeight(""), new TargetWeight(""),
new Height("")),
new Height(""), new Remark("")),
new Client(new Name("Irfan Ibrahim"), new Gender("Male"), new Phone("92492021"),
new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates"), new Birthday(""), new CurrentWeight(""), new TargetWeight(""),
new Height("")),
new Height(""), new Remark("")),
new Client(new Name("Roy Balakrishnan"), new Gender("Male"), new Phone("92624417"),
new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"), new Birthday(""), new CurrentWeight(""), new TargetWeight(""),
new Height(""))
new Height(""), new Remark(""))
};
}

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/address/storage/JsonAdaptedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import seedu.address.model.client.Height;
import seedu.address.model.client.Name;
import seedu.address.model.client.Phone;
import seedu.address.model.client.Remark;
import seedu.address.model.client.TargetWeight;
import seedu.address.model.tag.Tag;

Expand All @@ -40,6 +41,7 @@ class JsonAdaptedClient {
private final String height;
private final String targetWeight;
private final String currentWeight;
private final String remark;

/**
* Constructs a {@code JsonAdaptedClient} with the given client details.
Expand All @@ -50,7 +52,7 @@ public JsonAdaptedClient(@JsonProperty("name") String name,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("birthday") String birthday, @JsonProperty("tagged") List<JsonAdaptedTag> tagged,
@JsonProperty("currentWeight") String currentWeight, @JsonProperty("targetWeight") String targetWeight,
@JsonProperty("height") String height) {
@JsonProperty("height") String height, @JsonProperty("remark") String remark) {
this.name = name;
this.gender = gender;
this.phone = phone;
Expand All @@ -63,6 +65,7 @@ public JsonAdaptedClient(@JsonProperty("name") String name,
this.height = height;
this.currentWeight = currentWeight;
this.targetWeight = targetWeight;
this.remark = remark;
}

/**
Expand All @@ -81,6 +84,7 @@ public JsonAdaptedClient(Client source) {
height = source.getHeight().value;
currentWeight = source.getCurrentWeight().value;
targetWeight = source.getTargetWeight().value;
remark = source.getRemark().value;
}

/**
Expand Down Expand Up @@ -172,9 +176,15 @@ public Client toModelType() throws IllegalValueException {
}
final TargetWeight modelTargetWeight = new TargetWeight(targetWeight);

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<>(clientTags);
return new Client(modelName, modelGender, modelPhone, modelEmail, modelAddress, modelTags, modelBirthday,
modelCurrentWeight, modelTargetWeight, modelHeight);
modelCurrentWeight, modelTargetWeight, modelHeight, modelRemark);
}

}
Loading

0 comments on commit f8ea76d

Please sign in to comment.