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 status attribute + other minor fixes #108

Merged
merged 15 commits into from
Oct 23, 2024
Merged
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public static String format(Person person) {
.append("; Tier: ")
.append(person.getTier())
.append("; Remark: ")
.append(person.getRemark());
.append(person.getRemark())
.append("; Status: ")
.append(person.getStatus());
return builder.toString();
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NEW_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -32,7 +33,8 @@ public class AddCommand extends Command {
+ PREFIX_JOB + "JOB "
+ PREFIX_INCOME + "INCOME "
+ "[" + PREFIX_TIER + "TIER]...\n"
+ "[" + PREFIX_NEW_REMARK + "NEW REMARK]...\n"
+ "[" + PREFIX_NEW_REMARK + "NEW REMARK]..."
+ "[" + PREFIX_STATUS + "STATUS]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
Expand All @@ -41,7 +43,8 @@ public class AddCommand extends Command {
+ PREFIX_JOB + "doctor "
+ PREFIX_INCOME + "300 "
+ PREFIX_TIER + "GOLD "
+ PREFIX_NEW_REMARK + "He is very smart ";
+ PREFIX_NEW_REMARK + "He is very smart "
+ PREFIX_STATUS + "NON_URGENT";

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
public final class CommandCommons {
public static final String DEFAULT_TIER = "";
public static final String DEFAULT_REMARK = "NA";
public static final String DEFAULT_STATUS = "NONE";

}
30 changes: 23 additions & 7 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_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NEW_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

Expand All @@ -30,6 +31,7 @@
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.status.Status;
import seedu.address.model.tier.Tier;

/**
Expand All @@ -52,6 +54,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_TIER + "TIER]...\n"
+ "[" + PREFIX_NEW_REMARK + "NEW REMARK] "
+ "[" + PREFIX_APPEND_REMARK + "ADD-ON TO EXISTING REMARK] "
+ "[" + PREFIX_STATUS + "STATUS] "
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
Expand Down Expand Up @@ -109,16 +112,17 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Job updatedJob = editPersonDescriptor.getJob().orElse(personToEdit.getJob());
Income updatedIncome = editPersonDescriptor.getIncome().orElse(personToEdit.getIncome());
Tier updatedTier = editPersonDescriptor.getTiers().orElse(personToEdit.getTier());
Tier updatedTier = editPersonDescriptor.getTier().orElse(personToEdit.getTier());
Remark updatedRemark;
if (editPersonDescriptor.getAppendedRemark().isPresent()) {
updatedRemark = Remark.combineRemarks(personToEdit.getRemark(),
editPersonDescriptor.getAppendedRemark().get());
} else {
updatedRemark = editPersonDescriptor.getNewRemark().orElse(personToEdit.getRemark());
}
Status updatedStatus = editPersonDescriptor.getStatus().orElse(personToEdit.getStatus());
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedJob, updatedIncome,
updatedTier, updatedRemark);
updatedTier, updatedRemark, updatedStatus);
}

@Override
Expand Down Expand Up @@ -159,6 +163,7 @@ public static class EditPersonDescriptor {
private Tier tier;
private Remark remark;
private Remark appendedRemark;
private Status status;
public EditPersonDescriptor() {}

/**
Expand All @@ -175,13 +180,15 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setTier(toCopy.tier);
setNewRemark(toCopy.remark);
setAppendedRemark(toCopy.appendedRemark);
setStatus(toCopy.status);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, job, income, tier, remark, appendedRemark);
return CollectionUtil.isAnyNonNull(name, phone, email, address, job, income, tier, remark, appendedRemark,
status);
}

public void setName(Name name) {
Expand Down Expand Up @@ -235,16 +242,16 @@ public Optional<Income> getIncome() {
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
*/
public void setTier(Tier tiers) {
this.tier = tiers;
public void setTier(Tier tier) {
this.tier = tier;
}

/**
* Returns an unmodifiable tier, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
*/
public Optional<Tier> getTiers() {
public Optional<Tier> getTier() {
return (tier != null) ? Optional.of(tier) : Optional.empty();
}

Expand All @@ -263,6 +270,13 @@ public void setAppendedRemark(Remark remark) {
public Optional<Remark> getAppendedRemark() {
return Optional.ofNullable(appendedRemark);
}
public void setStatus(Status status) {
this.status = status;
}

public Optional<Status> getStatus() {
return Optional.ofNullable(this.status);
}

@Override
public boolean equals(Object other) {
Expand All @@ -284,7 +298,8 @@ public boolean equals(Object other) {
&& Objects.equals(income, otherEditPersonDescriptor.income)
&& Objects.equals(tier, otherEditPersonDescriptor.tier)
&& Objects.equals(remark, otherEditPersonDescriptor.remark)
&& Objects.equals(appendedRemark, otherEditPersonDescriptor.appendedRemark);
&& Objects.equals(appendedRemark, otherEditPersonDescriptor.appendedRemark)
&& Objects.equals(status, otherEditPersonDescriptor.status);
}

@Override
Expand All @@ -298,6 +313,7 @@ public String toString() {
.add("income", income)
.add("tier", tier)
.add("remark", remark)
.add("status", status)
.toString();
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NEW_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import java.util.stream.Stream;
Expand All @@ -23,6 +24,7 @@
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.status.Status;
import seedu.address.model.tier.Tier;

/**
Expand All @@ -39,7 +41,7 @@ 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_JOB,
PREFIX_INCOME, PREFIX_TIER, PREFIX_NEW_REMARK);
PREFIX_INCOME, PREFIX_TIER, PREFIX_NEW_REMARK, PREFIX_STATUS);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_JOB, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_INCOME)
Expand All @@ -48,17 +50,19 @@ public AddCommand parse(String args) throws ParseException {
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_JOB,
PREFIX_INCOME, PREFIX_TIER, PREFIX_NEW_REMARK);
PREFIX_INCOME, PREFIX_TIER, PREFIX_NEW_REMARK, PREFIX_STATUS);
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());
Job job = ParserUtil.parseJob(argMultimap.getValue(PREFIX_JOB).get());
Income income = ParserUtil.parseIncome(argMultimap.getValue(PREFIX_INCOME).get());
Tier tier = ParserUtil.parseTier(argMultimap.getValue(PREFIX_TIER).orElse(""));
Tier tier = ParserUtil.parseTier(argMultimap.getValue(PREFIX_TIER).orElse(CommandCommons.DEFAULT_TIER));
Remark remark = ParserUtil.parseNewRemark(argMultimap.getValue(PREFIX_NEW_REMARK)
.orElse(CommandCommons.DEFAULT_REMARK));
Person person = new Person(name, phone, email, address, job, income, tier, remark);
Status status =
ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).orElse(CommandCommons.DEFAULT_STATUS));
Person person = new Person(name, phone, email, address, job, income, tier, remark, status);
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 @@ -16,5 +16,6 @@ public class CliSyntax {
public static final Prefix PREFIX_REMARK = new Prefix("r/");
public static final Prefix PREFIX_NEW_REMARK = new Prefix("rn/");
public static final Prefix PREFIX_APPEND_REMARK = new Prefix("ra/");
public static final Prefix PREFIX_STATUS = new Prefix("s/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NEW_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import seedu.address.commons.core.index.Index;
Expand All @@ -32,7 +33,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_INCOME, PREFIX_JOB, PREFIX_TIER, PREFIX_NEW_REMARK, PREFIX_APPEND_REMARK);
PREFIX_INCOME, PREFIX_JOB, PREFIX_TIER, PREFIX_NEW_REMARK, PREFIX_APPEND_REMARK, PREFIX_STATUS);

Index index;

Expand All @@ -49,7 +50,7 @@ public EditCommand parse(String args) throws ParseException {
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_INCOME, PREFIX_JOB, PREFIX_TIER, PREFIX_NEW_REMARK, PREFIX_APPEND_REMARK);
PREFIX_INCOME, PREFIX_JOB, PREFIX_TIER, PREFIX_NEW_REMARK, PREFIX_APPEND_REMARK, PREFIX_STATUS);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand Down Expand Up @@ -81,6 +82,10 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setAppendedRemark(ParserUtil.parseNewRemark(
argMultimap.getValue(PREFIX_APPEND_REMARK).get()));
}
if (argMultimap.getValue(PREFIX_STATUS).isPresent()) {
editPersonDescriptor.setStatus((ParserUtil.parseStatus(
argMultimap.getValue(PREFIX_STATUS).get())));
}

if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
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 @@ -12,6 +12,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.status.Status;
import seedu.address.model.tier.Tier;
import seedu.address.model.util.IncomeComparisonOperator;

Expand Down Expand Up @@ -174,6 +175,21 @@ public static Tier parseTier(String tier) throws ParseException {
return new Tier(trimmedTier);
}

/**
* Parses a {@code String status} into a {@code Status}.
* Leading and trailing whitespaces are trimmed.
*
* @throws ParseException if the given {@code status} is invalid.
*/
public static Status parseStatus(String status) throws ParseException {
requireNonNull(status);
String trimmedStatus = status.trim();
if (!Status.isValidStatus(trimmedStatus)) {
throw new ParseException(Status.MESSAGE_CONSTRAINTS);
}
return new Status(trimmedStatus);
}

/**
* Parses a {@code String operator} into a {@code IncomeComparisonOperator}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Objects;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.status.Status;
import seedu.address.model.tier.Tier;

/**
Expand All @@ -20,21 +21,17 @@ public class Person {

// Data fields
private final Address address;

private final Job job;

private final Income income;

private final Tier tier;

private final Remark remark;

private final Status status;
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Job job, Income income,
Tier tier, Remark remark) {
requireAllNonNull(name, phone, email, address, tier, remark);
Tier tier, Remark remark, Status status) {
requireAllNonNull(name, phone, email, address, tier, remark, status);
this.name = name;
this.phone = phone;
this.email = email;
Expand All @@ -43,6 +40,7 @@ public Person(Name name, Phone phone, Email email, Address address, Job job, Inc
this.income = income;
this.tier = tier;
this.remark = remark;
this.status = status;
}

public Name getName() {
Expand All @@ -66,6 +64,9 @@ public Job getJob() {
public Income getIncome() {
return income;
}
public Status getStatus() {
return status;
}

/**
* Returns an immutable tier, which throws {@code UnsupportedOperationException}
Expand Down Expand Up @@ -110,17 +111,13 @@ public boolean equals(Object other) {
}

Person otherPerson = (Person) other;
return name.equals(otherPerson.name)
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& job.equals(otherPerson.job);
return isSamePerson(otherPerson);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, job, tier);
return Objects.hash(name, phone, email, address, job, tier, remark, status);
}

@Override
Expand All @@ -134,6 +131,7 @@ public String toString() {
.add("income", income)
.add("tier", tier)
.add("remark", remark)
.add("status", status)
.toString();
}

Expand Down
Loading