Skip to content

Commit cb63615

Browse files
authored
Merge pull request #44 from IronBiscuit/master
List Inventory
2 parents 4e80e61 + a7f16cf commit cb63615

20 files changed

Lines changed: 302 additions & 23 deletions

docs/AboutUs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: page
33
title: About Us
44
---
55

6-
We are a team based in the [School of Computing, National University of Singapore](http://www.comp.nus.edu.sg), formed
6+
We are a team based in the [School of Computing, National University of Singapore](http://www.comp.nus.edu.sg), formed
77
to fulfill the team project requirements of [CS2103T](https://nusmods.com/modules/CS2103T/software-engineering)
88

99
You can reach us at the email `seer[at]comp.nus.edu.sg`
@@ -64,7 +64,7 @@ You can reach us at the email `seer[at]comp.nus.edu.sg`
6464

6565
<img src="images/howtoosee.png" width="200px">
6666

67-
[[github](https://github.com/howtoosee)]
67+
[[github](https://github.com/howtoosee)]
6868
[[portfolio](team/xihao.md)]
6969

7070
* Role: Developer

docs/DeveloperGuide.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
264264
### Use cases
265265
For all use cases (unless specified otherwise):
266266
- The **System** is `NUStorage`
267-
- The **Actor** is `User`
267+
- The **Actor** is `User`
268268

269269

270270
**Use case: Add an inventory item**
@@ -277,7 +277,7 @@ For all use cases (unless specified otherwise):
277277
4. NUStorage adds the item to the list
278278

279279
Use case ends.
280-
280+
281281
**Use case: Remove an inventory item**
282282

283283
**MSS**
@@ -330,7 +330,7 @@ For all use cases (unless specified otherwise):
330330
* 3a1. NUStorage shows an error message.
331331

332332
Use case resumes at step 2.
333-
333+
334334
**Use case: List finance/inventory records**
335335

336336
**MSS**
@@ -341,7 +341,7 @@ For all use cases (unless specified otherwise):
341341
* 2a. The list is empty.
342342

343343
Use case ends.
344-
344+
345345
**Use case: Save finance / inventory records**
346346

347347
**MSS**
@@ -356,7 +356,7 @@ For all use cases (unless specified otherwise):
356356
1. User requests to exit NUStorage
357357
2. NUStorage saves both finance and inventory records and shows a goodbye message
358358
3. NUStorage terminates after 1.5 seconds
359-
359+
360360

361361

362362
### Non-Functional Requirements
@@ -371,7 +371,7 @@ For all use cases (unless specified otherwise):
371371

372372
* **Mainstream OS**: Windows, Linux, Unix, OS-X
373373
* **Inventory**: An item that a user wishes to record. An inventory item can refer to any existing object
374-
* **Finances**: A record that allows a user to monitor his earnings and spending.
374+
* **Finances**: A record that allows a user to monitor his earnings and spending.
375375

376376
--------------------------------------------------------------------------------------------------------------------
377377

@@ -403,7 +403,7 @@ testers are expected to do more *exploratory* testing.
403403
1. Shutting Down
404404

405405
1. If you would like to save your records prior to shutting down, remember to enter the `save` command
406-
406+
407407
1. Close the app by simply clicking on the close button or enter the `exit` command.
408408

409409
### Deleting a record
@@ -426,13 +426,13 @@ testers are expected to do more *exploratory* testing.
426426
1. Adding a financial/inventory record.
427427

428428
1. Prerequisites: None
429-
429+
430430
1. Test case: `add_inventory i/MacBook n/10`<br>
431431
Expected: An inventory item 'MacBook' is added with the quantity of 10. Details of the added record shown in the status message.
432-
432+
433433
1. Test case: `add_finance op/in amt/1000`
434434
Expected: A finance record of an increase by $1000.00 is added. Details of the added record shown in status message.
435-
435+
436436
1. Other incorrect add commands to try: `add`, `add_record`, `add_inventory i/MacBook` <br>
437437
Expected: No record is added. Error details shown in the status message.
438438

src/main/java/nustorage/logic/Logic.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import nustorage.logic.parser.exceptions.ParseException;
1010
import nustorage.model.ReadOnlyAddressBook;
1111
import nustorage.model.person.Person;
12+
import nustorage.model.record.InventoryRecord;
1213

1314
/**
1415
* API of the Logic component
@@ -33,6 +34,8 @@ public interface Logic {
3334
/** Returns an unmodifiable view of the filtered list of persons */
3435
ObservableList<Person> getFilteredPersonList();
3536

37+
ObservableList<InventoryRecord> getFilteredInventory();
38+
3639
/**
3740
* Returns the user prefs' address book file path.
3841
*/

src/main/java/nustorage/logic/LogicManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import nustorage.model.Model;
1616
import nustorage.model.ReadOnlyAddressBook;
1717
import nustorage.model.person.Person;
18+
import nustorage.model.record.InventoryRecord;
1819
import nustorage.storage.Storage;
1920

2021
/**
@@ -64,6 +65,10 @@ public ObservableList<Person> getFilteredPersonList() {
6465
return model.getFilteredPersonList();
6566
}
6667

68+
public ObservableList<InventoryRecord> getFilteredInventory() {
69+
return model.getFilteredInventory();
70+
}
71+
6772
@Override
6873
public Path getAddressBookFilePath() {
6974
return model.getAddressBookFilePath();

src/main/java/nustorage/logic/commands/AddInventoryCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public AddInventoryCommand(InventoryRecord newInventoryRecord, FinanceRecord new
3333
@Override
3434
public CommandResult execute(Model model) throws CommandException {
3535
requireNonNull(model);
36-
3736
model.addInventoryRecord(newInventoryRecord);
3837
model.addFinanceRecord(newFinanceRecord);
3938
return new CommandResult(String.format(MESSAGE_SUCCESS, newInventoryRecord));

src/main/java/nustorage/logic/commands/CommandResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class CommandResult {
1717
/** The application should exit. */
1818
private final boolean exit;
1919

20+
2021
/**
2122
* Constructs a {@code CommandResult} with the specified fields.
2223
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package nustorage.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static nustorage.model.Model.PREDICATE_SHOW_ALL_INVENTORY;
5+
6+
import javafx.collections.ObservableList;
7+
import nustorage.model.Model;
8+
import nustorage.model.record.InventoryRecord;
9+
10+
/**
11+
* Lists all persons in the address book to the user.
12+
*/
13+
public class ListInventoryCommand extends Command {
14+
15+
public static final String COMMAND_WORD = "list_inventory";
16+
17+
public static final String MESSAGE_SUCCESS = "Listed all inventory items!";
18+
19+
20+
@Override
21+
public CommandResult execute(Model model) {
22+
requireNonNull(model);
23+
model.updateFilteredInventoryList(PREDICATE_SHOW_ALL_INVENTORY);
24+
ObservableList<InventoryRecord> inventory = model.getFilteredInventory();
25+
return new CommandResult(MESSAGE_SUCCESS);
26+
}
27+
}

src/main/java/nustorage/logic/parser/AddressBookParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import nustorage.logic.commands.FindCommand;
1919
import nustorage.logic.commands.HelpCommand;
2020
import nustorage.logic.commands.ListCommand;
21+
import nustorage.logic.commands.ListInventoryCommand;
2122
import nustorage.logic.commands.ListFinanceRecordsCommand;
2223
import nustorage.logic.parser.exceptions.ParseException;
2324

@@ -47,6 +48,8 @@ public Command parseCommand(String userInput) throws ParseException {
4748
final String commandWord = matcher.group("commandWord");
4849
final String arguments = matcher.group("arguments");
4950
switch (commandWord) {
51+
case ListInventoryCommand.COMMAND_WORD:
52+
return new ListInventoryCommand();
5053

5154
case AddInventoryCommand.COMMAND_WORD:
5255
return new AddInventoryCommandParser().parse(arguments);

src/main/java/nustorage/model/Model.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public interface Model {
1919
/** {@code Predicate} that always evaluate to true */
2020
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
21+
Predicate<InventoryRecord> PREDICATE_SHOW_ALL_INVENTORY = unused -> true;
2122

2223
/**
2324
* Replaces user prefs data with the data in {@code userPrefs}.
@@ -92,9 +93,13 @@ public interface Model {
9293
/** Returns an unmodifiable view of the filtered person list */
9394
ObservableList<Person> getFilteredPersonList();
9495

96+
ObservableList<InventoryRecord> getFilteredInventory();
97+
9598
/**
9699
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
97100
* @throws NullPointerException if {@code predicate} is null.
98101
*/
99102
void updateFilteredPersonList(Predicate<Person> predicate);
103+
104+
void updateFilteredInventoryList(Predicate<InventoryRecord> predicate);
100105
}

src/main/java/nustorage/model/ModelManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ModelManager implements Model {
3131
private final AddressBook addressBook;
3232
private final UserPrefs userPrefs;
3333
private final FilteredList<Person> filteredPersons;
34+
private final FilteredList<InventoryRecord> filteredInventory;
3435

3536
/**
3637
* Initializes a ModelManager with the given addressBook and userPrefs.
@@ -42,6 +43,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs
4243
logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs);
4344

4445
this.inventory = new Inventory();
46+
filteredInventory = new FilteredList<>(this.inventory.asUnmodifiableObservableList());
4547
this.financeAccount = new FinanceAccount();
4648
this.addressBook = new AddressBook(addressBook);
4749
this.userPrefs = new UserPrefs(userPrefs);
@@ -93,6 +95,19 @@ public void addInventoryRecord(InventoryRecord newRecord) {
9395
inventory.addInventoryRecord(newRecord);
9496
}
9597

98+
public ObservableList<InventoryRecord> getFilteredInventory() {
99+
return filteredInventory;
100+
}
101+
102+
/**
103+
* Applies a predicate to the Inventory and returns those that pass it.
104+
* @param predicate the predicate used to filter Inventory
105+
*/
106+
public void updateFilteredInventoryList(Predicate<InventoryRecord> predicate) {
107+
requireNonNull(predicate);
108+
filteredInventory.setPredicate(predicate);
109+
}
110+
96111
//=========== FinanceAccount ================================================================================
97112

98113
@Override
@@ -163,6 +178,7 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
163178
filteredPersons.setPredicate(predicate);
164179
}
165180

181+
166182
@Override
167183
public boolean equals(Object obj) {
168184
// short circuit if same object

0 commit comments

Comments
 (0)