Skip to content

Commit ac7dd2c

Browse files
authored
Merge pull request #105 from junhaotan/master
Add notification popup window when product quantity drops below threshold
2 parents dbb622d + e7839cb commit ac7dd2c

File tree

9 files changed

+84
-10
lines changed

9 files changed

+84
-10
lines changed

docs/DeveloperGuide.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,42 @@ image::CommitActivityDiagram.png[]
235235
** Cons: Requires dealing with commands that have already been undone: We must remember to skip these commands. Violates Single Responsibility Principle and Separation of Concerns as `HistoryManager` now needs to do two different things.
236236
// end::undoredo[]
237237

238+
// tag::managecustomer[]
239+
=== Add delete/edit/clear/list/find customer feature
240+
The manage product mechanism is facilitated by `InventorySystemParser`.
241+
First, the InventorySystemParser class parses the user command.
242+
This results in a Command object which is executed by the LogicManager.
243+
The command execution modifies Model's customer list depending on the command.
244+
The result of the command execution is encapsulated as a CommandResult object which is passed back to the Ui.
245+
246+
The following commands are available to be parsed by InventorySystemParser:
247+
248+
* `AddCustomerCommand` -- Adds a customer into the customer list in the inventory system.
249+
* `ListCustomerCommand` -- Lists all customers in the customer list.
250+
* `ClearCustomerCommand` -- Clears all customers in the customer list.
251+
* `DeleteCustomerCommand` -- Deletes a customer from the customer list in the inventory system.
252+
* `EditCustomerCommand` -- Edits a customer details (name, phone, email, address, tags)
253+
* `FindCustomerCommand` -- Finds customer with name containing given keyword(s)
254+
255+
The commands all inherit from superclass `Command`. Only add, delete, edit and find commands require a command parser to parse the arguments entered by the user.
256+
257+
The following sequence diagram shows how the add operation works:
258+
259+
image::AddCustomerSequenceDiagram.png[]
260+
261+
The following sequence diagram shows how the list operation works:
262+
263+
image::ListCustomerSequenceDiagram.png[]
264+
265+
The following sequence diagram shows how the edit operation works:
266+
267+
image::EditCustomerSequenceDiagram.png[]
268+
269+
The following activity diagram summarizes what happens when a user executes a command that changes the product list in the model:
270+
271+
image::ProductActivityDiagram.png[]
272+
273+
// end::managecustomer[]
238274

239275
// tag::manageproduct[]
240276
=== [Proposed] Add/ delete/ edit/ clear/ list/ find product feature
72.8 KB
Loading
70.1 KB
Loading
48.7 KB
Loading

src/main/java/seedu/address/commons/core/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public class Messages {
1515
public static final String MESSAGE_TRANSACTIONS_LISTED_OVERVIEW = "%1$d transactions listed!";
1616
public static final String MESSAGE_INVALID_TRANSACTION_DISPLAYED_INDEX =
1717
"The transaction index provided is invalid";
18+
public static final String MESSAGE_INVALID_THRESHOLD_AMOUNT = "Threshold amount must be more than 0!";
1819
}

src/main/java/seedu/address/logic/commands/product/LowLimitCommand.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package seedu.address.logic.commands.product;
22

3+
import static seedu.address.logic.commands.product.EditProductCommand.EditProductDescriptor;
4+
import static seedu.address.logic.commands.product.EditProductCommand.createEditedProduct;
35
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT;
46
import static seedu.address.logic.parser.CliSyntax.PREFIX_THRESHOLD;
57
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PRODUCTS;
68

9+
import java.util.List;
10+
11+
import seedu.address.commons.core.Messages;
712
import seedu.address.commons.core.index.Index;
813
import seedu.address.logic.commands.Command;
914
import seedu.address.logic.commands.CommandResult;
1015
import seedu.address.logic.commands.exceptions.CommandException;
1116
import seedu.address.model.Model;
1217
import seedu.address.model.product.Product;
1318
import seedu.address.model.util.QuantityThreshold;
19+
import seedu.address.ui.NotificationWindow;
1420

1521
/**
1622
* Sets the product low limit threshold for notifications.
@@ -31,6 +37,7 @@ public class LowLimitCommand extends Command {
3137
public static final String MESSAGE_SUCCESS = "New threshold set: %1$s";
3238

3339
private final Index productIndex;
40+
private final EditProductDescriptor editProductDescriptor = new EditProductDescriptor();
3441
private QuantityThreshold threshold;
3542

3643
public LowLimitCommand(Index productIndex, QuantityThreshold threshold) {
@@ -40,10 +47,29 @@ public LowLimitCommand(Index productIndex, QuantityThreshold threshold) {
4047

4148
@Override
4249
public CommandResult execute(Model model) throws CommandException {
43-
Product product = model.getFilteredProductList().get(productIndex.getZeroBased());
44-
product.setThreshold(threshold.toString());
50+
List<Product> lastShownList = model.getFilteredProductList();
51+
52+
if (productIndex.getZeroBased() >= lastShownList.size()) {
53+
throw new CommandException(Messages.MESSAGE_INVALID_PRODUCT_DISPLAYED_INDEX);
54+
}
55+
56+
Product productToEdit = lastShownList.get(productIndex.getZeroBased());
57+
int thresholdValue = Integer.parseInt(threshold.value);
58+
if (thresholdValue > 0) {
59+
editProductDescriptor.setThreshold(threshold);
60+
} else {
61+
throw new CommandException(Messages.MESSAGE_INVALID_THRESHOLD_AMOUNT);
62+
}
63+
64+
Product editedProduct = createEditedProduct(productToEdit, editProductDescriptor);
65+
model.setProduct(productToEdit, editedProduct);
4566
model.updateFilteredProductList(PREDICATE_SHOW_ALL_PRODUCTS);
4667

47-
return new CommandResult(String.format(MESSAGE_SUCCESS, product));
68+
if (editedProduct.getQuantity().value < thresholdValue) {
69+
NotificationWindow window = new NotificationWindow();
70+
window.show(editedProduct.getDescription(), editedProduct.getQuantity());
71+
}
72+
73+
return new CommandResult(String.format(MESSAGE_SUCCESS, editedProduct));
4874
}
4975
}

src/main/java/seedu/address/logic/commands/transaction/AddTransactionCommand.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import seedu.address.model.transaction.Transaction;
2424
import seedu.address.model.transaction.TransactionFactory;
2525
import seedu.address.model.util.Quantity;
26+
import seedu.address.ui.NotificationWindow;
2627

2728
/**
2829
* Adds a transaction to the system.
@@ -64,8 +65,13 @@ public CommandResult execute(Model model) throws CommandException {
6465
List<Product> lastShownList = model.getFilteredProductList();
6566

6667
Index productIndex = transactionFactory.getProductIndex();
68+
Index customerIndex = transactionFactory.getCustomerIndex();
6769

6870
if (productIndex.getZeroBased() >= lastShownList.size()) {
71+
throw new CommandException(Messages.MESSAGE_INVALID_PRODUCT_DISPLAYED_INDEX);
72+
}
73+
74+
if (customerIndex.getZeroBased() >= lastShownList.size()) {
6975
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
7076
}
7177

@@ -86,9 +92,17 @@ public CommandResult execute(Model model) throws CommandException {
8692
throw new CommandException(MESSAGE_DUPLICATE_TRANSACTION);
8793
}
8894

95+
int thresholdValue = Integer.parseInt(editedProduct.getThreshold().value);
96+
97+
if (editedProduct.getQuantity().value < thresholdValue) {
98+
NotificationWindow window = new NotificationWindow();
99+
window.show(editedProduct.getDescription(), editedProduct.getQuantity());
100+
}
101+
89102
model.setProduct(productToEdit, editedProduct);
90103
model.updateFilteredProductList(PREDICATE_SHOW_ALL_PRODUCTS);
91104

105+
92106
Transaction toAdd = transactionFactory.createTransaction(model);
93107

94108
if (model.hasTransaction(toAdd)) {

src/main/java/seedu/address/model/product/Product.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import seedu.address.model.util.Description;
99
import seedu.address.model.util.Quantity;
1010
import seedu.address.model.util.QuantityThreshold;
11-
import seedu.address.ui.NotificationWindow;
1211

1312
/**
1413
* Represents a Product in the product list.
@@ -79,12 +78,6 @@ public QuantityThreshold getThreshold() {
7978

8079
public void setThreshold(String quantityThreshold) {
8180
this.threshold = new QuantityThreshold(quantityThreshold);
82-
int numQuantity = quantity.value;
83-
int thresholdValue = Integer.parseInt(quantityThreshold);
84-
if (numQuantity <= thresholdValue) {
85-
NotificationWindow window = new NotificationWindow();
86-
window.show(description, quantity);
87-
}
8881
}
8982

9083
/**

src/main/java/seedu/address/model/transaction/TransactionFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public Index getProductIndex() {
4747
return productIndex;
4848
}
4949

50+
public Index getCustomerIndex() {
51+
return customerIndex;
52+
}
53+
5054
public Quantity getQuantity() {
5155
return quantity;
5256
}

0 commit comments

Comments
 (0)