Skip to content

Commit

Permalink
Merge pull request #385 from NaychiMin/380-decode-negative-dish-qty-v2.1
Browse files Browse the repository at this point in the history
Task 375, 380 Add additional error handling to decode orders.txt.
  • Loading branch information
ShaniceTang authored Nov 13, 2023
2 parents 173bc37 + 4a5519d commit d8bfe96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/main/java/seedu/cafectrl/storage/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ private static void decodeSalesData(String orderLine, ArrayList<OrderList> order
float totalOrderCost = quantity * decodedDishPrice;

checkNameValidity(dishName);
boolean isDataAccurate = isCompleteStatusAccurate(orderLine, completeStatus);
boolean isDataAccurate = isCompleteStatusAccurate(orderLine, completeStatus)
&& isValidQty(orderLine, quantity)
&& isValidPrice(orderLine, decodedDishPrice);
if (!isDataAccurate) {
return;
}
Expand All @@ -294,6 +296,22 @@ private static boolean isCompleteStatusAccurate(String orderLine, String complet
return false;
}

private static boolean isValidPrice(String orderLine, Float decodedDishPrice) {
if (decodedDishPrice >= 0) {
return true;
}
ui.showToUser(ErrorMessages.INVALID_DISH_PRICE + orderLine);
return false;
}

private static boolean isValidQty(String orderLine, int quantity) {
if (quantity > 0) {
return true;
}
ui.showToUser(ErrorMessages.INVALID_ORDER_QTY + orderLine);
return false;
}

//@@author Cazh1
/**
* Increases the size of the orderlist when there is gap between the previous order and the next
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/cafectrl/ui/ErrorMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public class ErrorMessages {
public static final String INVALID_ORDER_DATA = "orders.txt: Dish is not in current menu, "
+ "this order will be removed -> ";
public static final String INVALID_ORDER_STATUS = "orders.txt: Invalid status, this order will be removed -> ";
public static final String INACCURATE_ORDER_COST_DATA = "orders.txt: The total order cost of this order -> \"%s\" "
+ "is inaccurate and will hence be updated from %.2f to %.2f instead.";
public static final String INVALID_ORDER_QTY = "orders.txt: Invalid quantity (order quantity has to be more than 0)"
+ ", this order will be removed -> ";
public static final String INVALID_DISH_PRICE = "orders.txt: Invalid dish price, this order will be removed -> ";
public static final String WRONG_HELP_FORMAT = "Invalid help command format!\n"
+ HelpCommand.MESSAGE_USAGE;
public static final String WRONG_LIST_TOTAL_SALES_FORMAT = "Invalid list_total_sales command format!\n"
Expand Down

0 comments on commit d8bfe96

Please sign in to comment.