Skip to content

Commit

Permalink
Merge pull request #69 from zengzihui/merge-seller-buyer
Browse files Browse the repository at this point in the history
Merge the working add buyer + add seller + delete + view all contact lists into Master branch
  • Loading branch information
zengzihui authored Mar 21, 2024
2 parents 2b40469 + b0f2372 commit 7c0c42c
Show file tree
Hide file tree
Showing 24 changed files with 860 additions and 96 deletions.
16 changes: 8 additions & 8 deletions src/main/java/seedu/address/logic/commands/AddBuyerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSINGTYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSING_TYPE;
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_TAG;
Expand All @@ -18,25 +18,25 @@
*/
public class AddBuyerCommand extends Command {

public static final String COMMAND_WORD = "addbuyer";
public static final String COMMAND_WORD = "addBuyer";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a buyer to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a buyer to EstateEase. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_HOUSINGTYPE + "HOUSINGTYPE"
+ PREFIX_HOUSING_TYPE + "HOUSING_TYPE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_HOUSINGTYPE + "HDB "
+ PREFIX_HOUSING_TYPE + "HDB "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

public static final String MESSAGE_SUCCESS = "New buyer added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This buyer already exists in the address book";
public static final String MESSAGE_DUPLICATE_BUYER = "This buyer already exists in EstateEase";

private final Person buyerToAdd;

Expand All @@ -46,7 +46,7 @@ public class AddBuyerCommand extends Command {
*/
public AddBuyerCommand(Person person) {
requireNonNull(person);
buyerToAdd = person;
this.buyerToAdd = person;
}
/**
* Executes the command and returns the result message.
Expand All @@ -60,7 +60,7 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(buyerToAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
throw new CommandException(MESSAGE_DUPLICATE_BUYER);
}

model.addPerson(buyerToAdd);
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_BLOCK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSING_TYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LEVEL;
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_STREET;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_UNITNUMBER;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Adds a person to the address book. Currently obsolete
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_HOUSING_TYPE + "HOUSINGTYPE"
+ PREFIX_STREET + "STREET "
+ PREFIX_BLOCK + "BLOCK "
+ PREFIX_LEVEL + "LEVEL "
+ PREFIX_UNITNUMBER + "UNITNUMBER "
+ PREFIX_POSTALCODE + "POSTAL CODE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_HOUSING_TYPE + "HDB "
+ PREFIX_STREET + "Clementi Ave 2 "
+ PREFIX_BLOCK + "311 "
+ PREFIX_LEVEL + "02 "
+ PREFIX_UNITNUMBER + "25 "
+ PREFIX_POSTALCODE + "578578 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

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";

private final Person toAdd;

/**
* Creates an AddCommand to add the specified {@code Person}
*/
public AddCommand(Person person) {
requireNonNull(person);
toAdd = person;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

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

// instanceof handles nulls
if (!(other instanceof AddCommand)) {
return false;
}

AddCommand otherAddCommand = (AddCommand) other;
return toAdd.equals(otherAddCommand.toAdd);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("toAdd", toAdd)
.toString();
}
}
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/AddSellerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_BLOCK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSINGTYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSING_TYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LEVEL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -23,14 +23,14 @@
*/
public class AddSellerCommand extends Command {

public static final String COMMAND_WORD = "addseller";
public static final String COMMAND_WORD = "addSeller";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a seller to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a seller to EstateEase. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_HOUSINGTYPE + "HOUSINGTYPE "
+ PREFIX_HOUSING_TYPE + "HOUSING_TYPE "
+ PREFIX_STREET + "STREET "
+ PREFIX_BLOCK + "BLOCK "
+ PREFIX_LEVEL + "LEVEL "
Expand All @@ -41,7 +41,7 @@ public class AddSellerCommand extends Command {
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_HOUSINGTYPE + "HDB "
+ PREFIX_HOUSING_TYPE + "HDB "
+ PREFIX_STREET + "Clementi Ave 2 "
+ PREFIX_BLOCK + "311 "
+ PREFIX_LEVEL + "02 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSINGTYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSING_TYPE;
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_TAG;
Expand Down Expand Up @@ -30,23 +30,22 @@ public class AddBuyerCommandParser implements Parser<AddBuyerCommand> {
*/
public AddBuyerCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSINGTYPE,
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE,
PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSINGTYPE)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddBuyerCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_HOUSINGTYPE);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE);
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());
String housingtype = ParserUtil.parseHousing(argMultimap.getValue(PREFIX_HOUSINGTYPE).get());
String housingType = ParserUtil.parseHousing(argMultimap.getValue(PREFIX_HOUSING_TYPE).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, housingtype, tagList);
Person person = new Person(name, phone, email, housingType, tagList);

return new AddBuyerCommand(person);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_BLOCK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSINGTYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSING_TYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LEVEL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -45,20 +45,20 @@ public class AddSellerCommandParser implements Parser<AddSellerCommand> {
public AddSellerCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_HOUSINGTYPE, PREFIX_LEVEL,
PREFIX_HOUSING_TYPE, PREFIX_LEVEL,
PREFIX_BLOCK, PREFIX_STREET, PREFIX_UNITNUMBER, PREFIX_POSTALCODE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSINGTYPE,
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE,
PREFIX_POSTALCODE, PREFIX_STREET, PREFIX_UNITNUMBER) || !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddSellerCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_HOUSINGTYPE, PREFIX_LEVEL,
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_HOUSING_TYPE, PREFIX_LEVEL,
PREFIX_EMAIL, PREFIX_BLOCK, PREFIX_STREET, PREFIX_UNITNUMBER, 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());
String housingType = ParserUtil.parseHousing(argMultimap.getValue(PREFIX_HOUSINGTYPE).get());
String housingType = ParserUtil.parseHousing(argMultimap.getValue(PREFIX_HOUSING_TYPE).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

boolean hasBlock = argMultimap.getValue(PREFIX_BLOCK).isPresent();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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_TAG = new Prefix("t/");
public static final Prefix PREFIX_HOUSINGTYPE = new Prefix("type/");
public static final Prefix PREFIX_HOUSING_TYPE = new Prefix("type/");
public static final Prefix PREFIX_STREET = new Prefix("street/");
public static final Prefix PREFIX_LEVEL = new Prefix("level/");
public static final Prefix PREFIX_UNITNUMBER = new Prefix("unitNo/");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSINGTYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSING_TYPE;
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_TAG;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSINGTYPE,
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE,
PREFIX_TAG);

Index index;
Expand All @@ -44,7 +44,7 @@ public EditCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSINGTYPE);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand All @@ -57,9 +57,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}
if (argMultimap.getValue(PREFIX_HOUSINGTYPE).isPresent()) {
if (argMultimap.getValue(PREFIX_HOUSING_TYPE).isPresent()) {
editPersonDescriptor.setHousingType(ParserUtil.parseHousing(argMultimap
.getValue(PREFIX_HOUSINGTYPE).get()));
.getValue(PREFIX_HOUSING_TYPE).get()));
}

parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);
Expand Down
34 changes: 13 additions & 21 deletions src/main/java/seedu/address/model/person/Buyer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,35 @@

import java.util.Set;

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

/**
* Represents a buyer in the address book.
*/
public class Buyer extends Person {

/** The house associated with the buyer. */
private final House house;

/**
* Constructs a new Buyer instance without specifying a house. Default constructor.
*
* @param name The name of the buyer.
* @param phone The phone number of the buyer.
* @param email The email address of the buyer.
* @param housingtype The type of housing the buyer wants.
* @param housingType The type of housing the buyer wants.
* @param tags The tags associated with the buyer.
*/
public Buyer(Name name, Phone phone, Email email, String housingtype, Set<Tag> tags) {
super(name, phone, email, housingtype, tags);
this.house = null;
public Buyer(Name name, Phone phone, Email email, String housingType, Set<Tag> tags) {
super(name, phone, email, housingType, tags);
}

/**
* Constructs a new Buyer instance with a specified house. Meant for potential future Purchase methods.
*
* @param name The name of the buyer.
* @param phone The phone number of the buyer.
* @param email The email address of the buyer.
* @param housingtype The type of housing the buyer wants.
* @param house The house associated with the buyer.
* @param tags The tags associated with the buyer.
*/
public Buyer(Name name, Phone phone, Email email, String housingtype, House house, Set<Tag> tags) {
super(name, phone, email, housingtype, tags);
this.house = house;
@Override
public String toString() {
return new ToStringBuilder(this)
.add("name", super.getName())
.add("phone", super.getPhone())
.add("email", super.getEmail())
.add("housing type", super.getHousingType())
.add("tags", super.getTags())
.toString();
}
}
Loading

0 comments on commit 7c0c42c

Please sign in to comment.