Skip to content

Commit

Permalink
Merge pull request #281 from ziyi105/master
Browse files Browse the repository at this point in the history
Update error message
  • Loading branch information
DextheChik3n authored Nov 8, 2023
2 parents f3cef62 + 186fc1f commit dd27c57
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
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 @@ -13,7 +13,7 @@ public class EditPriceCommand extends Command {
public static final String COMMAND_WORD = "edit_price";
public static final String MESSAGE_USAGE = "To edit price of a menu item: \n"
+ "edit_price dish/DISH_INDEX price/NEW_PRICE\n"
+ "Example: edit_price index/1 price/4.50";
+ "Example: edit_price dish/1 price/4.50";

protected Menu menu;
protected Ui ui;
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/seedu/cafectrl/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Parser implements ParserUtil {
/** The rest of Command Handler Patterns*/
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "dish/(.*) price/(.*)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "dish/(.*)\\sprice/(.*)";
private static final String BUY_INGREDIENT_ARGUMENT_STRING = "(ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+"
+ "(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
private static final String SHOW_SALE_BY_DAY_ARGUMENT_STRING = "day/(\\d+)";
Expand Down Expand Up @@ -179,7 +179,13 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u
float newPrice;

try {
String dishIndexText = matcher.group(dishIndexGroup).replaceAll("\\s", "");
String dishIndexText = matcher.group(dishIndexGroup).trim();

// Check whether the index is empty
if (dishIndexText.equals("")) {
return new IncorrectCommand(ErrorMessages.MISSING_DISH_IN_EDIT_PRICE, ui);
}

dishIndex = Integer.parseInt(dishIndexText);

// Check whether the dish index is valid
Expand Down Expand Up @@ -304,8 +310,12 @@ static float parsePriceToFloat(String priceText) throws ParserException {
final Pattern priceTwoDecimalPlacePattern = Pattern.compile("^-?[0-9]\\d*(\\.\\d{0,2})?$");
Matcher priceMatcher = priceTwoDecimalPlacePattern.matcher(trimmedPriceText);

// Check whether price text is empty
if (priceText.equals("")) {
throw new ParserException(ErrorMessages.MISSING_PRICE);
}
if (!priceMatcher.matches()) {
throw new ParserException(ErrorMessages.PRICE_TOO_MANY_DECIMAL_PLACES);
throw new ParserException(ErrorMessages.WRONG_PRICE_TYPE_FOR_EDIT_PRICE);
}

float price;
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/seedu/cafectrl/ui/ErrorMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class ErrorMessages {
+ "for delete command.";
public static final String MISSING_ARGUMENT_FOR_BUY_INGREDIENT = "Error: Missing arguments "
+ "for buy ingredient command.";
public static final String WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE = "Error: "
+ "Invalid argument type. \n "
+ "Make sure dish index is of type int";
public static final String WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE = "Something is wrong with "
+ "the dish index! Could you make sure that is it of type int \n"
+ "and do not type in multiple dish indexes at one time!";
public static final String WRONG_PRICE_TYPE_FOR_EDIT_PRICE = "Error: "
+ "Invalid price! \n "
+ "Price can only have 2 decimal place and it must be "
+ "within the range of 0.00 to 1000000!";
+ "Price must be a float and within the range of "
+ "0.00 to 1000000 with up to 2 decimal place";
public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Unknown command. "
+ "Type 'help' to view the accepted list of commands";
public static final String INVALID_DISH_INDEX = "Do we even have this dish? "
Expand Down Expand Up @@ -59,4 +59,8 @@ public class ErrorMessages {
+ "for the 'day' field!";
public static final String EDIT_SAME_PRICE = "New price is exactly the same as old price,"
+ " is that what you want?";
public static final String MISSING_PRICE = "Did you forget to include price? Just a reminder: "
+ "price can only have up to 2 decimal place!";
public static final String MISSING_DISH_IN_EDIT_PRICE = "Sorry, I didnt catch the dish index, "
+ "did you forget to include it in your command?";
}
2 changes: 1 addition & 1 deletion src/test/java/seedu/cafectrl/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void showToUser(String... message) {
ParserUtil parserUtil = new Parser();
Command commandReturned = parserUtil.parseCommand(menu, testUserInput, ui, pantry, sales, currentDate);
commandReturned.execute();
assertEquals(ErrorMessages.WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE, actualOutput.get(0));
assertEquals(ErrorMessages.MISSING_DISH_IN_EDIT_PRICE, actualOutput.get(0));
}

@Test
Expand Down

0 comments on commit dd27c57

Please sign in to comment.