Skip to content

Commit

Permalink
Merge branch 'master' into rename-ppp
Browse files Browse the repository at this point in the history
  • Loading branch information
NaychiMin authored Nov 13, 2023
2 parents b1096d9 + 4abbf3f commit bc62c5b
Show file tree
Hide file tree
Showing 36 changed files with 419 additions and 167 deletions.
38 changes: 37 additions & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* [Pantry-calculateMaxDish()](#pantry---calculatemaxdish)
* [Delete Dish](#delete-dish)
* [Edit Price](#edit-price)
* [View Total Stock](#view-total-stock)
* [Buy Ingredient](#buy-ingredient)
* [Help](#help)
* [**Future Enhancements**](#future-enhancements)
* [Create an interface for `Pantry`](#create-an-interface-for-pantry)
Expand Down Expand Up @@ -79,11 +81,20 @@ The bulk of the app’s work is done by the following components:

### How the architecture components interact with each other

The Sequence Diagram below shows how the components interact with each other for the scenario where the user issues the command `delete 1`.
The Sequence Diagram below shows how the components interact with each other for the scenario where the user issues the command `bye`.

![Architecture Encode Data](images/sequence/Architecture_Encode_Data.png)
<br>*Figure 2: Architecture Encode Sequence Diagram*

1. User enters the command `bye` to the `Ui`
2. `Ui` passes the command as a string through the method `receiveUserInput('bye')` in `CafeCtrl`
3. `CafeCtrl` passes the string to `Parser` through the method `parseCommand('bye')`
4. `Parser` returns a new `exitCommand` object
5. `CafeCtrl` calls the `execute()` method of `Command` and returns after execution is completed (Step 6)
6. `CafeCtrl` calls the `saveAll()` command in `Storage` before terminating the application
7. `saveMenu()`, `saveOrderList()`, and `savePantryStock` are executed within the `saveAll()` method (Steps 8 - 13)
8. Application terminates.

### Ui component
API: [Ui.java]({repoURL}src/main/java/seedu/cafectrl/ui/Ui.java)

Expand Down Expand Up @@ -351,6 +362,31 @@ API: [EditPriceCommand.java]({repoURL}src/main/java/seedu/cafectrl/command/EditP

When the `execute()` method of `EditPriceCommand` is invoked in `Main`, it subsequently calls the `setPrice()` method on the `Dish` object to modify the price of the specific dish. Following this, the `showEditPriceMessages()` method in the `Ui` component is triggered to retrieve and display a message from `Messages` related to the successful execution of the price modification process. This sequence of actions orchestrates the flow of information and operations between the `Main`, `EditPriceCommand`, `Dish`, and `Ui` components, ensuring the seamless handling of the price editing functionality within the application.

### View Total Stock
![View Total Stock Execution](images/sequence/ViewTotalStockCommand_execute.png)

*Figure 16: Execution of view_stock command*

API: [ViewTotalStockCommand.java]({repoURL}src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java)

When the `execute()` method of `ViewTotalStock` is invoked, an ArrayList of Ingredients are retrieved through the method `getPantryStock`. For each ingredient in the ArrayList, `ViewTotalStock` calls `showIngredientStock` from `Ui` to print out the list of ingredients in the ArrayList.

### Buy Ingredient
![Buy Ingredient Execution](images/sequence/BuyIngredientCommand_execute.png)

*Figure 17: Execution of buy_ingredient command*

API: [BuyIngredientCommand.java]({repoURL}src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java)

When the `execute()` method is invoked
1. `addIngredient` in `BuyIngredientCommand` is called
2. Looping from the **first to the last** element in an ArrayList of Ingredients called `ingredients`, `addIngredientToStock` from `Pantry` is invoked
3. First, `pantryStock` is retrieved and `getIndexOfIngredient` is called to check if the new ingredient exists in `pantryStock`
4. If ingredient exists (`ingredientIndex != -1`), `addIngredientQuantity` is called to update the quantity of the existing ingredient
5. Else, a new `ingredient` object is returned
6. Looping from the **last to the first** element in `ingredients`, the ingredient is added to the string to be printed `ingredientString` using the `buildBuyIngredientMessage` method which ignores repeated ingredients in the list
7. Finally, `ingredientString` is shown to the user through `showToUser` method of `Ui`

### Help

![Help Execution](images/sequence/HelpCommand_execute.png)
Expand Down
10 changes: 5 additions & 5 deletions docs/diagrams/ArchitectureDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rectangle {
rectangle Ui
rectangle Parser
rectangle Command
rectangle Main
rectangle CafeCtrl
rectangle Data
rectangle Storage
}
Expand All @@ -22,10 +22,10 @@ Command --> Data
Command ..> Ui
Storage --> Data
Storage ...> TextFiles
Ui <- Main
Main --> Parser
Main --> Data
Main --> Storage
Ui <- CafeCtrl
CafeCtrl --> Parser
CafeCtrl --> Data
CafeCtrl --> Storage


@enduml
78 changes: 38 additions & 40 deletions docs/diagrams/sequence/Architecture_Encode_Data.puml
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
@startuml
!define COMMAND class ListIngredientCommand
!define UI class Ui
!define MAIN class Main
!define STORAGE class Storage
!define DATA class Data
!define PARSER class Parser
!define COMMAND class Command

autonumber
Actor user

loop userInput != "bye"
user->Ui : 'delete 1'
activate Ui
Ui-> Main : userInput : String
activate Main
Main -> Parser : parseCommand()
Activate Parser
Parser -> Main : command: Command
Deactivate Parser
Main -> Command : delete.execute()
Activate Command
Command -> Data : menu.remove()
Activate Data
return
return
user -> Ui: 'bye'
Ui-> Main : userInput : String
end loop
Main->Storage : saveMenu()
Activate Storage
Storage -> Storage: encodeMenu()
Activate Storage
return
return
return
return

@enduml
@startuml
!define UI class ":Ui"
!define MAIN class ":CafeCtrl"
!define STORAGE class ":Storage"
!define DATA class ":Data"
!define PARSER class ":Parser"
!define COMMAND class ":Command"

autonumber
Actor user

user -> ":Ui": 'bye'
Activate ":Ui"
":Ui"-> ":CafeCtrl" : receiveUserInput('bye')
loop !exitCommand
Activate ":CafeCtrl"
":CafeCtrl" -> ":Parser" : parseCommand('bye')
Activate ":Parser"
return exitCommand: ":Command"
":CafeCtrl" -> ":Command" : exitCommand.execute()
Activate ":Command"
return
end loop
":CafeCtrl"->":Storage" : saveAll()
Activate ":Storage"
":Storage" -> ":Storage": saveMenu()
Activate ":Storage"
return
":Storage" -> ":Storage": saveOrderList()
Activate ":Storage"
return
":Storage" -> ":Storage": savePantryStock()
Activate ":Storage"
return
return
return

@enduml
48 changes: 48 additions & 0 deletions docs/diagrams/sequence/BuyIngredientCommand_execute.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@startuml
!define COMMAND class ":BuyIngredientCommand"
!define UI class ":Ui"
!define MENU class ":Menu"
!define PANTRY class ":Pantry"

autonumber

-> ":BuyIngredientCommand" : execute()
activate ":BuyIngredientCommand"

":BuyIngredientCommand" -> ":BuyIngredientCommand" : addIngredient()
activate ":BuyIngredientCommand"
loop i < ingredients.size()
":BuyIngredientCommand" -> ":Pantry" : addIngredientToStock(name: String, qty: int, unit: String)
activate ":Pantry"
":Pantry" -> ":Pantry" : getPantryStock()
activate ":Pantry"
return pantryStock: ArrayList<Ingredient>

":Pantry" -> ":Pantry" : getIndexOfIngredient(name: String)
activate ":Pantry"
return ingredientIndex: int
alt ingredientIndex != -1
":Pantry" -> ":Pantry" : addIngredientQuantity(qty: int, ingredientIndex: int, unit: String)
activate ":Pantry"
return ingredient: Ingredient
":Pantry" --> ":BuyIngredientCommand" : ingredient: Ingredient
else
return ingredient: Ingredient
end
end loop

loop i >= 0
":BuyIngredientCommand" -> ":BuyIngredientCommand" : buildBuyIngredientMessage(ingredient: Ingredient)
activate ":BuyIngredientCommand"
return ingredientString: String
end loop

return
":BuyIngredientCommand" -> ":Ui" : showToUser(ingredientString: String)
activate ":Ui"
return
return



@enduml
25 changes: 25 additions & 0 deletions docs/diagrams/sequence/ViewTotalStockCommand_execute.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@startuml
!define COMMAND class ":ViewTotalStockCommand"
!define UI class ":Ui"
!define PANTRY class ":Pantry"

autonumber

-> ":ViewTotalStockCommand" : execute()
activate ":ViewTotalStockCommand"

":ViewTotalStockCommand" -> ":Pantry" : getPantryStock().get(dishIndexToBeDeleted: int)
activate ":Pantry"
return (pantryStock: ArrayList<Ingredients>)
loop Ingredient ingredient : pantryStock
":ViewTotalStockCommand" -> ":Ui" : showIngredientStock(name: String, qty: int, unit: String)
activate ":Ui"
":Ui" -> ":Ui" : showToUser(message: String)
activate ":Ui"
return
return
end loop
return


@enduml
Binary file modified docs/images/ArchitectureDiagram.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/aboutUs/shanice.jpg
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/sequence/Architecture_Encode_Data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images_PPP/shanice/bug_reporting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 25 additions & 17 deletions docs/team/shanicetang.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ Café proprietors who prefer typing on CLI than any other interaction method and
#### Features

1. **Delete Dish** <br>
- Function: Allow user to delete a specific dish on the menu
- Command Format: `delete DISH_INDEX`<br>
- Error Handling: This command is able to detect missing argument tag, missing argument, and invalid index. The error message will be shown to the user.
<br/><br/>
- Function: Allow user to delete a specific dish on the menu
- Command Format: `delete DISH_INDEX`<br>
- Error Handling: This command is able to detect missing argument tag, missing argument, and invalid index. The error message will be shown to the user.
<br/><br/>
2. **Buy Ingredient** <br>
- Function: Allow user to add ingredients to the Pantry. If ingredients have been previously added, its quantity will update accordingly<br>
- Command Format: `buy_ingredient ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY[, ingredient/INGREDIENT2_NAME qty/INGREDIENT2_QTY, ...]`<br>
- Error Handling: This command is able to detect the following user errors and outputs the appropriate error messages<br>
- Missing argument tag / Missing arguments
- Quantity value less than 1 or greater than 1,000,000
- Empty / Invalid Units
- Function: Allow user to add ingredients to the Pantry. If ingredients have been previously added, its quantity will update accordingly<br>
- Command Format: `buy_ingredient ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY[, ingredient/INGREDIENT2_NAME qty/INGREDIENT2_QTY, ...]`<br>
- Error Handling: This command is able to detect the following user errors and outputs the appropriate error messages<br>
- Missing argument tag / Missing arguments
- Quantity value less than 1 or greater than 1,000,000
- Empty / Invalid Units

3. **View Total Stock** <br>
- Function: Allows user to view the total stock currently in the Pantry
- Command Format: `view_stock`
- Function: Allows user to view the total stock currently in the Pantry
- Command Format: `view_stock`

### Enhancement
1. **Storage**<br>
Expand All @@ -46,10 +46,10 @@ Café proprietors who prefer typing on CLI than any other interaction method and
<br><br>
2. **Parser**<br>
- Implemented parsing for the features listed above
- Improved precision of error handling by adding some checking methods: isInvalidQty, isEmptyUnit, isValidUnit
- Improved precision of error handling by adding some checking methods: `isInvalidQty`, `isEmptyUnit`, `isValidUnit`, `checkForMismatchUnit`
<br><br>
3. **Pantry**<br>
- Implemented pantry class which helps user to keep track of their current stock. This enhancement plays a huge role to several commands as it allows the user to smoothly interact with the pantry, hence it is important to ensure its completeness by ensuring it is able to seamlessly handle pantry-related operations. For example, for my contribution to pantry class (adding of ingredients to stock), I had to consider the user adding the same ingredients within an input or using a different unit and handle those possibilities elegantly.
- Implemented pantry class together with @NaychiMin which helps user to keep track of their current stock. This enhancement plays a huge role to several commands as it allows the user to smoothly interact with the pantry, hence it is important to ensure its completeness by ensuring it is able to seamlessly handle pantry-related operations. For example, for my contribution to pantry class (adding of ingredients to stock), I had to consider the user adding the same ingredients within an input or using a different unit and handle those possibilities elegantly.
- Allows user to add ingredients to pantry (through `buy_ingredient`) and updates the quantity of existing ingredients. This was a challenge to implement mostly due to the need to upkeep to coding quality. I had to achieve this without involving arrowhead code (which would have been the trivial solution) through abstraction and understanding what parameters I need to pass in and return.
- Ensures user uses the same unit for existing ingredients. To allow this to be implemented, I modified the Ingredient class upon approval from my team members to accept units as a separate attribute and helped modify other classes/methods that instantiates an Ingredient object.
4. **Messages & ErrorMessages**<br>
Expand All @@ -63,15 +63,23 @@ Café proprietors who prefer typing on CLI than any other interaction method and
### Contributions to DG
[DeveloperGuide](https://ay2324s1-cs2113-t17-2.github.io/tp/DeveloperGuide.html)
- Designed various UML diagrams: Architecture Diagram, Ui Component Class Diagram, Data Component Class Diagram, Delete Sequence Diagram
- Added descriptions for Ui component and Delete Command
- Added descriptions for Ui component, Delete Command, View Total Stock Command, and Buy Ingredient Command

#### Team-based Task
1. **Logging**
- This was challenging as I encountered the issue of the log messages being printed out to system console which ruined the Ui. :( The CS2113 textbook did not mention how to rectify this issue, so I had to do external research and eventually found a solution to store log messages into a log file without displaying at runtime. :)
- This was challenging as I encountered the issue of the log messages being printed out to system console which ruined the Ui. :( The CS2113 textbook did not mention how to rectify this issue, so I had to do external research and eventually found a solution to store log messages into a log file without displaying at runtime. :)
2. **Maintaining issue tracker**
3. **Testing application and report bugs found**
![](../images_PPP/shanice/bug_reporting.png)

### Review / Mentoring Contributions
1. Reviewed and merged some PRs [#300](https://github.com/AY2324S1-CS2113-T17-2/tp/pull/300), ...
1. Reviewed and merged some PRs [#300](https://github.com/AY2324S1-CS2113-T17-2/tp/pull/300), [#322](https://github.com/AY2324S1-CS2113-T17-2/tp/pull/322), [#283](https://github.com/AY2324S1-CS2113-T17-2/tp/pull/283), ...
2. Clarified and updated the team before making major changes to ensure everyone is on the same page <3
- Ensuring unused methods can be safely deleted with permission from the team member who wrote it
![](../images_PPP/shanice/deleting_unused_method.png)
![](../images_PPP/shanice/deleting_unused_method2.png)
- Ensuring team members give their permission before implementing
![](../images_PPP/shanice/ensure_permission_given.png)

### Contributions Beyond the Project Team
1. Reported bugs in other teams' application: [#105](https://github.com/AY2324S1-CS2113-W12-3/tp/issues/105), [#101](https://github.com/AY2324S1-CS2113-W12-3/tp/issues/101)
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/seedu/cafectrl/CafeCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@
*/
public class CafeCtrl {

private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());
private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName());
private final Ui ui;
private Menu menu;
private final Storage storage;
private final Pantry pantry;
private final Menu menu;
private final Sales sales;
private final CurrentDate currentDate;

private Command command;
private Pantry pantry;
private Sales sales;
private CurrentDate currentDate;
private Storage storage;

/**
* Private constructor for the CafeCtrl class, used for initializing the user interface and menu list.
*/

private CafeCtrl() {
initLogger();
this.ui = new Ui();
this.storage = new Storage(this.ui);
this.sales = new Sales();
this.menu = this.storage.loadMenu();
this.pantry = this.storage.loadPantryStock();
this.menu = this.storage.loadMenu();
this.sales = this.storage.loadOrderList(menu);
this.currentDate = new CurrentDate(sales);

Expand All @@ -59,6 +58,7 @@ private CafeCtrl() {
private void run() {
ui.showWelcome();
ui.printLine();

do {
try {
String fullUserInput = ui.receiveUserInput();
Expand All @@ -82,8 +82,9 @@ private void initLogger() {
logger.setUseParentHandlers(false);
try {
FileHandler fileHandler = new FileHandler("cafeCtrl.log");
logger.addHandler(fileHandler);
SimpleFormatter formatter = new SimpleFormatter();

logger.addHandler(fileHandler);
fileHandler.setFormatter(formatter);
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -94,6 +95,4 @@ public static void main(String[] args) {
CafeCtrl cafeCtrl = new CafeCtrl();
cafeCtrl.run();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private void buildBuyIngredientMessage(Ingredient ingredient) {
}
ingredientsToBePrinted.add(ingredient);
ingredientString += "Ingredient: " + ingredient.getName()
+ "\t\tQty: " + ingredient.getQty()
+ ingredient.getUnit() + "\n";
+ "\nQty: " + ingredient.getQty()
+ ingredient.getUnit() + "\n\n";
}
}

2 changes: 1 addition & 1 deletion src/main/java/seedu/cafectrl/command/EditPriceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EditPriceCommand extends Command {
+ "edit_price dish/DISH_INDEX price/NEW_PRICE\n"
+ "Example: edit_price dish/1 price/4.50";

private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());
private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName());
protected Menu menu;
protected Ui ui;
private final int menuID;
Expand Down
Loading

0 comments on commit bc62c5b

Please sign in to comment.