Skip to content

Commit

Permalink
Merge pull request #262 from wang-h-z/bugFixes
Browse files Browse the repository at this point in the history
Massive Bug Extermination
  • Loading branch information
wang-h-z authored Nov 6, 2024
2 parents 375077a + 38ece50 commit e4f2d97
Show file tree
Hide file tree
Showing 34 changed files with 281 additions and 69 deletions.
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 @@ -55,7 +55,9 @@ public static String format(Person person) {
.append(person.getAppointment())
.append("; Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
return String.format("%1s.\nPhone number: %2s and Email: %3s",
person.getName(), person.getPhone(), person.getEmail());
//return builder.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
*/
public class DeleteClientProfileCommand extends Command {

public static final String COMMAND_WORD = "delete";
public static final String COMMAND_WORD = "deleteclient";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the client profile corresponding to the client's name.\n"
+ "Parameters: CLIENT_NAME (case-insensitive)\n"
+ "Example: " + COMMAND_WORD + " Tan Wen Xuan";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Successfully deleted %1$s "
+ "with the number: %2$s " + "and email: %3$s!";
public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Successfully deleted %1$s ";
private final Name targetName;
private final boolean skipConfirmation;

Expand Down Expand Up @@ -91,8 +90,7 @@ public CommandResult execute(Model model) throws CommandException {
model.updateFilteredListingList(listing -> true);

model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS,
personToDelete.getName(), personToDelete.getPhone(), personToDelete.getEmail()));
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public CommandResult execute(Model model) throws CommandException {
}

model.setPerson(personToEdit, editedPerson);
model.updateListingsAfterClientEdit(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredListingList(listing -> true);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_TO;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -33,11 +32,13 @@ public class AddAppointmentCommand extends Command {
+ PREFIX_DATE + " [DATE in ddMMyy] "
+ PREFIX_FROM + " [FROM] "
+ PREFIX_TO + " [TO]\n"
+ "Example: " + COMMAND_WORD + " Sean Dias "
+ "Example: " + COMMAND_WORD + " Alex Yeoh "
+ "d/ 201224 fr/ 0800 to/ 1000";

public static final String MESSAGE_ADD_APPOINTMENT_SUCCESS = "Appointment scheduled for %1$s";
public static final String MESSAGE_UPDATE_APPOINTMENT_SUCCESS = "Updated appointment scheduled for %1$s";
public static final String MESSAGE_ADD_APPOINTMENT_SUCCESS = "Appointment scheduled for %1$s on:\n"
+ "%2$s";
public static final String MESSAGE_UPDATE_APPOINTMENT_SUCCESS = "Updated appointment scheduled for %1$s on:\n"
+ "%2$s";
public static final String MESSAGE_INVALID_PERSON = "This person does not exist in the address book.";
public static final String MESSAGE_INVALID_PERIOD =
"Invalid from and to timings! From timing cannot be after to timing.";
Expand Down Expand Up @@ -95,7 +96,7 @@ private String generateSuccessMessage(Person personToEdit) {
String message = personToEdit.hasAppointment()
? MESSAGE_ADD_APPOINTMENT_SUCCESS
: MESSAGE_UPDATE_APPOINTMENT_SUCCESS;
return String.format(message, Messages.format(personToEdit));
return String.format(message, personToEdit.getName(), appointment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import seedu.address.model.person.Buyer;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Seller;

/**
* Adds a listing to the address book.
Expand Down Expand Up @@ -58,6 +59,7 @@ public class AddListingCommand extends Command {

public static final String MESSAGE_SUCCESS = "New listing added: %1$s";
public static final String MESSAGE_NOT_SELLER = "The seller specified is not a seller";
public static final String MESSAGE_NOT_BUYER = "The buyer(s) specified is not a buyer";
public static final String MESSAGE_DUPLICATE_LISTING = "This listing already exists in EZSTATE";
private final Name listingName;
private final Price price;
Expand Down Expand Up @@ -97,7 +99,7 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_INPUT);
}

if (seller instanceof Buyer) {
if (!(seller instanceof Seller)) {
throw new CommandException(MESSAGE_NOT_SELLER);
}

Expand All @@ -109,6 +111,9 @@ public CommandResult execute(Model model) throws CommandException {
if (!lastShownList.contains(buyer)) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_INPUT);
}
if (!(buyer instanceof Buyer)) {
throw new CommandException(MESSAGE_NOT_BUYER);
}

personBuyers.add(buyer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRICE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REGION;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_LISTINGS;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -102,6 +103,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.setListing(listingToEdit, editedListing);
model.updateFilteredListingList(PREDICATE_SHOW_ALL_LISTINGS);
return new CommandResult(String.format(MESSAGE_EDIT_LISTING_SUCCESS, Messages.format(editedListing)));
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ public static Area parseArea(String area) throws ParseException {
if (!Area.isValidArea(areaTrimmed)) {
throw new ParseException(Area.MESSAGE_CONSTRAINTS);
}
int intArea = Integer.parseInt(areaTrimmed);
return new Area(intArea);
return new Area(areaTrimmed);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ public interface Model {
*/
boolean hasListingsForBuyer(Person buyer);

// Returns the listing with the same name as {@code listing} exists in the address book.
//Person getPersonByName(Name name);

/** Returns an unmodifiable view of the filtered person list */
ObservableList<Listing> getFilteredListingList();

Expand All @@ -183,4 +180,10 @@ public interface Model {
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredListingList(Predicate<Listing> predicate);

/**
* Updates relevant Listings when there is a change made to a Client
* Replaces all listings with the personToEdit with editedPerson.
*/
void updateListingsAfterClientEdit(Person personToEdit, Person editedPerson);
}
33 changes: 33 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;
import java.util.logging.Logger;

Expand All @@ -12,8 +13,10 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.listing.Listing;
import seedu.address.model.person.Buyer;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Seller;

/**
* Represents the in-memory model of the address book data.
Expand Down Expand Up @@ -204,6 +207,36 @@ public boolean canEditListing(Listing toEdit, Listing editedListing) {
|| editedListing.getAddress().equals(currentListing.getAddress()));
}

/**
* Updates listings associated with a client after the client's details have been edited.
* If the edited person is a buyer, it replaces the buyer in all relevant listings.
* If the edited person is a seller, it replaces all listings associated with that seller.
*
* @param personToEdit The original person to be edited.
* @param editedPerson The edited person with updated details.
*/
@Override
public void updateListingsAfterClientEdit(Person personToEdit, Person editedPerson) {
if (this.hasListingsForSeller(personToEdit) || this.hasListingsForBuyer(personToEdit)) {
if (personToEdit instanceof Buyer buyerToEdit) {

this.getListings().getListingList()
.forEach(listing -> listing.replaceBuyer(buyerToEdit, editedPerson));

} else if (personToEdit instanceof Seller sellerToEdit) {

List<Listing> listingsToDelete = this.getListings().getListingList().stream()
.filter(listing -> listing.getSeller().equals(sellerToEdit))
.toList();

for (Listing listing : listingsToDelete) {
this.deleteListing(listing);
this.addListing(listing.modifyListingWithSeller(editedPerson));
}
}
}
}

//=========== Filtered Person List Accessors =============================================================

/**
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/seedu/address/model/listing/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
*/
public class Area {
public static final String MESSAGE_CONSTRAINTS =
"Area should only contain numbers, and it should be at least 2 digits long";
private static final String VALIDATION_REGEX = "\\d{2,}";
"Area should only contain positive numbers and cannot start with zeroes, "
+ "and it should be at least 2 digits long";
private static final String VALIDATION_REGEX = "^[1-9]\\d{1,}$";

private final Integer squareMeters;
private final String squareMeters;

/**
* Constructs a {@code Area}.
*
* @param squareMeters The size of the listing in square meters.
*/
public Area(int squareMeters) {
public Area(String squareMeters) {
this.squareMeters = squareMeters;
}

public int getArea() {
public String getArea() {
return this.squareMeters;
}

Expand All @@ -33,7 +34,7 @@ public static boolean isValidArea(String test) {

@Override
public String toString() {
return String.format("%d", this.squareMeters);
return String.format("%s", this.squareMeters);
}

@Override
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/seedu/address/model/listing/Listing.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ public void removeBuyer(Person buyer) {
buyers.remove(buyer);
}

/**
* Replaces a buyer from this listing's buyers.
* @param buyerToRemove The buyer to be removed.
* @param buyerToAdd The new buyer to add to the listing.
*/
public void replaceBuyer(Person buyerToRemove, Person buyerToAdd) {
if (buyers.contains(buyerToRemove)) {
buyers.remove(buyerToRemove);
buyers.add(buyerToAdd);
}
}

/**
* Checks if this listing has the specified buyer.
*
* @param buyer The buyer to check.
* @return True if the listing has the buyer, false otherwise.
*/
public boolean hasBuyer(Person buyer) {
return buyers.contains(buyer);
}

/**
* Returns a new Listing with a different seller
* @param sellerToAdd The new buyer to add to the listing.
* @return Listing with a modified seller.
*/
public Listing modifyListingWithSeller(Person sellerToAdd) {
return new Listing(name, address, price, area, region, sellerToAdd, buyers);
}

/**
* Checks if the given listing is the same listing as the current listing.
* Two listings are considered the same if they have the same address or name.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/listing/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
*/
public class Price {
public static final String MESSAGE_CONSTRAINTS =
"Price should only contain numbers, and it should be at least 6 digits long";
private static final String VALIDATION_REGEX = "\\d{6,}";
"Price should only contain positive numbers and cannot start with zeroes, "
+ "and it should be at least 6 digits long";
private static final String VALIDATION_REGEX = "^[1-9]\\d{5,}$";

private final String formattedValue;
private final BigDecimal rawValue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static ReadOnlyAddressBook getSampleAddressBook() {
public static Listing[] sampleListings() {
return new Listing[] {
new Listing(new Name("RC4"), new Address("134 Clementi Ave"),
new Price("200000", new BigDecimal("2000")), new Area(100),
new Price("200000", new BigDecimal("2000")), new Area("100"),
Region.WEST, BERNICE, new HashSet<>()),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Listing toModelType() throws IllegalValueException {
throw new IllegalValueException(Area.MESSAGE_CONSTRAINTS);
}

final Area modelArea = new Area(Integer.parseInt(area));
final Area modelArea = new Area(area);

if (region == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Region.class.getSimpleName()));
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public void execute_addBuyerProfile_success() throws Exception {

Buyer expectedBuyer = new PersonBuilder(AMY).buildBuyer();

// Adjust the expected message to match the actual message format
String expectedMessage = String.format("New buyer added: %s; Phone: %s; Email: %s; Appointment: "
+ "-; Tags: ",
String expectedMessage = String.format("New buyer added: %1s.\nPhone number: %2s and Email: %3s",
expectedBuyer.getName(), expectedBuyer.getPhone(), expectedBuyer.getEmail());

model.addPerson(expectedBuyer);
Expand All @@ -97,9 +95,7 @@ public void execute_addSellerProfile_success() throws Exception {
.withTags() // No tags
.buildSeller();

// Construct the expected message based on the actual format produced by the application
String expectedMessage = String.format("New seller added: %s; Phone: %s; Email: %s; Appointment: "
+ "-; Tags: ",
String expectedMessage = String.format("New seller added: %1s.\nPhone number: %2s and Email: %3s",
expectedSeller.getName(), expectedSeller.getPhone(), expectedSeller.getEmail());

// Execute the command and check for success
Expand All @@ -109,7 +105,7 @@ public void execute_addSellerProfile_success() throws Exception {
@Test
public void execute_commandExecutionError_throwsCommandException() {
Name invalidName = new Name("aaaaaaaaaaaaaaa");
String deleteCommand = "delete " + invalidName;
String deleteCommand = "deleteclient " + invalidName;
assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_INPUT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class CommandTestUtil {

public static final String VALID_NAME_PASIR_RIS = "Pasir Ris Condo";
public static final String VALID_ADDRESS_PASIR_RIS = "123 Pasir Ris Drive 3";
public static final int VALID_AREA_PASIR_RIS = 75;
public static final String VALID_AREA_PASIR_RIS = "75";
public static final String VALID_PRICE_PASIR_RIS = "700000";
public static final String VALID_REGION_PASIR_RIS = "East";
public static final String VALID_SELLER_PASIR_RIS = VALID_NAME_AMY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void execute_validBuyerNameUnfilteredList_success() {
new DeleteClientProfileCommand(personToDelete.getName(), true); // skipConfirmation = true

String expectedMessage = String.format(DeleteClientProfileCommand.MESSAGE_DELETE_PERSON_SUCCESS,
personToDelete.getName(), personToDelete.getPhone(), personToDelete.getEmail());
Messages.format(personToDelete));

Model expectedModel =
new ModelManager(model.getAddressBook(), new UserPrefs(), TypicalListings.getTypicalListings());
Expand All @@ -64,7 +64,7 @@ public void execute_validSellerNameUnfilteredList_success() {
new DeleteClientProfileCommand(personToDelete.getName(), true); // skipConfirmation = true

String expectedMessage = String.format(DeleteClientProfileCommand.MESSAGE_DELETE_PERSON_SUCCESS,
personToDelete.getName(), personToDelete.getPhone(), personToDelete.getEmail());
Messages.format(personToDelete));

Model expectedModel =
new ModelManager(model.getAddressBook(), new UserPrefs(), TypicalListings.getTypicalListings());
Expand Down Expand Up @@ -96,7 +96,7 @@ public void execute_validNameFilteredList_success() {
DeleteClientProfileCommand deleteCommand = new DeleteClientProfileCommand(personToDelete.getName());

String expectedMessage = String.format(DeleteClientProfileCommand.MESSAGE_DELETE_PERSON_SUCCESS,
personToDelete.getName(), personToDelete.getPhone(), personToDelete.getEmail());
Messages.format(personToDelete));

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), new Listings());
expectedModel.deletePerson(personToDelete);
Expand Down
Loading

0 comments on commit e4f2d97

Please sign in to comment.