Skip to content

Commit

Permalink
Merge pull request #101 from billyhoce/userguide-update-gui-details
Browse files Browse the repository at this point in the history
Update user guide, gui screenshots and link to user guide
  • Loading branch information
billyhoce authored Apr 4, 2024
2 parents 3cf2364 + 2fcd937 commit 1ff188a
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 134 deletions.
145 changes: 71 additions & 74 deletions docs/UserGuide.md

Large diffs are not rendered by default.

Binary file modified docs/images/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/findAlexDavidResult.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/helpMessage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 19 additions & 23 deletions src/main/java/seedu/address/logic/commands/AddOrderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.item.Item;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.orders.Order;

Expand All @@ -34,37 +35,37 @@ public class AddOrderCommand extends Command {

public static final String MESSAGE_ITEM_NOT_FOUND = "Item not found in the inventory";

public final NameContainsKeywordsPredicate personNamePredicate;
public final Name name;
public final String itemName;
public final int quantity;

public final LocalDateTime orderDateTime;

/**
* @param personNamePredicate of the person to add the order to
* @param name of the person to add the order to
* @param itemName name of item ordered
* @param quantity of specified item ordered
*/
public AddOrderCommand(NameContainsKeywordsPredicate personNamePredicate, String itemName, int quantity) {
requireAllNonNull(personNamePredicate, itemName, quantity);
public AddOrderCommand(Name name, String itemName, int quantity) {
requireAllNonNull(name, itemName, quantity);

this.personNamePredicate = personNamePredicate;
this.name = name;
this.itemName = itemName;
this.quantity = quantity;
this.orderDateTime = null;
}

/**
* @param personNamePredicate of the person to add the order to
* @param name of the person to add the order to
* @param itemName name of item ordered
* @param quantity of specified item ordered
* @param orderDateTime of the order
*/
public AddOrderCommand(NameContainsKeywordsPredicate personNamePredicate, String itemName,
public AddOrderCommand(Name name, String itemName,
int quantity, LocalDateTime orderDateTime) {
requireAllNonNull(personNamePredicate, itemName, quantity, orderDateTime);
requireAllNonNull(name, itemName, quantity, orderDateTime);

this.personNamePredicate = personNamePredicate;
this.name = name;
this.itemName = itemName;
this.quantity = quantity;
this.orderDateTime = orderDateTime;
Expand All @@ -75,20 +76,15 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();

// Find first person in filtered list matching the personNamePredicate
Person personToUpdate = null;
for (Person person : lastShownList) {
if (!personNamePredicate.test(person)) {
continue;
} else {
personToUpdate = person;
break;
}
}
if (isNull(personToUpdate)) {
Optional<Person> personOptional = lastShownList.stream()
.filter(person -> person.getName().fullName.toLowerCase().contains(this.name.fullName.toLowerCase()))
.findFirst();
if (personOptional.isEmpty()) {
throw new CommandException(Messages.MESSAGE_PERSON_NOT_FOUND);
}

Person personToUpdate = personOptional.get();

//Find matching item in catalogue
AddressBook addressBook = (AddressBook) model.getAddressBook();
Item item = addressBook.findItem(itemName);
Expand Down Expand Up @@ -128,14 +124,14 @@ public boolean equals(Object other) {
}

AddOrderCommand e = (AddOrderCommand) other;
return personNamePredicate.equals(e.personNamePredicate)
return name.equals(e.name)
&& itemName.equals(e.itemName) && (quantity == e.quantity);
}

@Override
public String toString() {
return "AddOrderCommand{"

Check warning on line 133 in src/main/java/seedu/address/logic/commands/AddOrderCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddOrderCommand.java#L133

Added line #L133 was not covered by tests
+ "personNamePredicate=" + personNamePredicate
+ "personNamePredicate=" + name
+ ", itemName='" + itemName + '\''
+ ", quantity=" + quantity
+ ", orderDateTime=" + orderDateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_QTY;

import java.util.Arrays;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddOrderCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Name;
import seedu.address.model.person.orders.Order;

/**
Expand All @@ -34,8 +33,7 @@ public AddOrderCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddOrderCommand.MESSAGE_USAGE));
}

String trimmedName = argMultimap.getValue(PREFIX_NAME).get().trim();
String[] nameKeywords = trimmedName.split("\\s+");
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).orElse(""));

// Item name should not be empty
String trimmedItemName = argMultimap.getValue(PREFIX_ITEM).get().trim();
Expand All @@ -53,8 +51,7 @@ public AddOrderCommand parse(String args) throws ParseException {
throw new ParseException(Order.MESSAGE_INVALID_QUANTITY);
}

return new AddOrderCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords)),
trimmedItemName, quantity);
return new AddOrderCommand(name, trimmedItemName, quantity);
}

private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class HelpWindow extends UiPart<Stage> {

public static final String USERGUIDE_URL = "https://se-education.org/addressbook-level3/UserGuide.html";
public static final String USERGUIDE_URL = "https://ay2324s2-cs2103t-t13-4.github.io/tp/UserGuide.html";
public static final String HELP_MESSAGE = "Refer to the user guide: " + USERGUIDE_URL;

private static final Logger logger = LogsCenter.getLogger(HelpWindow.class);
Expand Down
34 changes: 13 additions & 21 deletions src/test/java/seedu/address/logic/commands/AddOrderCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Test;

Expand All @@ -22,41 +20,39 @@
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.item.Item;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.testutil.PersonBuilder;

public class AddOrderCommandTest {

@Test
public void constructor_nullNameContainsKeywordsPredicate_throwsNullPointerException() {
public void constructor_nullName_throwsNullPointerException() {
assertThrows(NullPointerException.class, () ->
new AddOrderCommand(null, "itemName", 1));
}

@Test
public void constructor_nullOrder_throwsNullPointerException() {
assertThrows(NullPointerException.class, () ->
new AddOrderCommand(new NameContainsKeywordsPredicate(Collections.singletonList("test")), null, 0));
new AddOrderCommand(new Name("test"), null, 0));
}

@Test
public void execute_personFoundInFilteredPersonList_success() {
public void execute_nameMatchesPersonInFilteredPersonList_success() {
Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

String itemName = "Kaya Toast";
int points = 200;

model.addItem(new Item(itemName, points));

List<String> predicate = Collections.singletonList("benson");

NameContainsKeywordsPredicate bensonPredicate = new NameContainsKeywordsPredicate(predicate);
Name name = new Name("benson");
int quantity = 3;
LocalDateTime orderDateTime = LocalDateTime.parse("2024-01-01T07:00:00");

AddOrderCommand addOrderToSecondTypicalPerson =
new AddOrderCommand(bensonPredicate, itemName, quantity, orderDateTime);
new AddOrderCommand(name, itemName, quantity, orderDateTime);

Person bensonWithAddedOrder = new PersonBuilder(BENSON).withOrders(
// existing orders
Expand All @@ -77,18 +73,17 @@ public void execute_personFoundInFilteredPersonList_success() {
}

@Test
public void execute_personNotFoundInFilteredPersonList_throwsCommandException() {
public void execute_nameDoesNotMatchAnyPersonInFilteredPersonList_throwsCommandException() {
Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

List<String> predicate = Collections.singletonList("nobody");
Name name = new Name("nobodyShouldMatchThis");

NameContainsKeywordsPredicate nobodyPredicate = new NameContainsKeywordsPredicate(predicate);
String itemName = "Kaya Toast";
int quantity = 1;
LocalDateTime orderDateTime = LocalDateTime.parse("2024-01-01T07:00:00");

AddOrderCommand addOrderToSecondTypicalPerson =
new AddOrderCommand(nobodyPredicate, itemName, quantity, orderDateTime);
new AddOrderCommand(name, itemName, quantity, orderDateTime);

assertThrows(CommandException.class, Messages.MESSAGE_PERSON_NOT_FOUND, () ->
addOrderToSecondTypicalPerson.execute(model));
Expand All @@ -98,15 +93,12 @@ public void execute_personNotFoundInFilteredPersonList_throwsCommandException()
public void execute_itemNotInAddressBook_throwsCommandException() {
Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

List<String> predicate = Collections.singletonList("alice");

NameContainsKeywordsPredicate alicePredicate = new NameContainsKeywordsPredicate(predicate);
String itemName = "Non-existent Item";
int quantity = 1;
LocalDateTime orderDateTime = LocalDateTime.parse("2024-01-01T07:00:00");

AddOrderCommand addOrderToSecondTypicalPerson =
new AddOrderCommand(alicePredicate, itemName, quantity, orderDateTime);
new AddOrderCommand(ALICE.getName(), itemName, quantity, orderDateTime);

assertThrows(CommandException.class, MESSAGE_ITEM_NOT_FOUND, () ->
addOrderToSecondTypicalPerson.execute(model));
Expand All @@ -121,9 +113,9 @@ public void generateSuccessMessage_properPersonPassedIn_success() {

@Test
public void equals() {
NameContainsKeywordsPredicate johnny1 = new NameContainsKeywordsPredicate(Collections.singletonList("Johnny"));
NameContainsKeywordsPredicate johnny2 = new NameContainsKeywordsPredicate(Collections.singletonList("Johnny"));
NameContainsKeywordsPredicate walker = new NameContainsKeywordsPredicate(Collections.singletonList("Walker"));
Name johnny1 = new Name("Johnny");
Name johnny2 = new Name("Johnny");
Name walker = new Name("Walker");

String itemName1 = "Kaya Toast";
int quantity1 = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.ORDER_ITEM_COOKIES;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ORDER_COOKIES;
import static seedu.address.testutil.Assert.assertThrows;

import java.util.Arrays;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.AddOrderCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Name;
import seedu.address.model.person.orders.Order;

public class AddOrderCommandParserTest {
private AddOrderCommandParser parser = new AddOrderCommandParser();

@Test
public void parse_allFieldsPresent_success() {
NameContainsKeywordsPredicate expectedNamePred =
new NameContainsKeywordsPredicate(Arrays.asList("Bob", "Choo"));

try {
AddOrderCommand actualCommand = parser.parse(NAME_DESC_BOB + ORDER_ITEM_COOKIES);
AddOrderCommand expectedCommand = new AddOrderCommand(expectedNamePred, VALID_ORDER_COOKIES, 1);
AddOrderCommand expectedCommand = new AddOrderCommand(new Name(VALID_NAME_BOB), VALID_ORDER_COOKIES, 1);
assertEquals(actualCommand, expectedCommand);
} catch (ParseException pe) {
fail("Invalid userInput");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_POINTS;
import static seedu.address.testutil.Assert.assertThrows;
Expand Down Expand Up @@ -118,11 +119,11 @@ public void parseCommand_addMemPoints() throws Exception {
@Test
public void parseCommand_addOrder() throws Exception {
AddOrderCommand command = (AddOrderCommand) parser.parseCommand("addorder n/Amy Bee i/Cupcake q/1");
NameContainsKeywordsPredicate namePred = new NameContainsKeywordsPredicate(Arrays.asList("Amy", "Bee"));
Name name = new Name(VALID_NAME_AMY);
String itemName = "Cupcake";
int quantity = 1;

assertEquals(new AddOrderCommand(namePred, itemName, quantity), command);
assertEquals(new AddOrderCommand(name, itemName, quantity), command);
}

@Test
Expand Down

0 comments on commit 1ff188a

Please sign in to comment.