diff --git a/src/main/java/seedu/situs/parser/Parser.java b/src/main/java/seedu/situs/parser/Parser.java index bd8f24efbd..f38bcff8b6 100644 --- a/src/main/java/seedu/situs/parser/Parser.java +++ b/src/main/java/seedu/situs/parser/Parser.java @@ -16,7 +16,6 @@ import seedu.situs.ingredients.Ingredient; - import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeParseException; @@ -44,7 +43,9 @@ public class Parser { private static final String EXPIRY_FORMAT_ERROR_MESSAGE = "Invalid expiry date format!" + '\n' + "Please key in the expiry date in the format dd/mm/yyyy!"; private static final String INVALID_ALERT_TYPE_MESSAGE = "Not an alert type!"; + private static final String INVALID_THRESHOLD_TYPE_MESSAGE = "Not a threshold type!"; private static final String SET_THRESHOLD_ERROR_MESSAGE = "Error in setting threshold"; + private static final String INVALID_THRESHOLD_MESSAGE = "Thresholds cannot be less than or equal to 0"; private static final String SPACE_SEPARATOR = " "; private static final String EMPTY_STRING = ""; @@ -347,13 +348,21 @@ private static String parseSetCommand(String command) throws SitusException { try { switch (details[1].trim()) { case "expiry": - AlertExpiringSoonCommand.setExpiryThreshold(Long.parseLong(details[2].trim())); - return "Successfully set expiry threshold to " + details[2].trim() + " days"; + long newExpiryThreshold = Long.parseLong(details[2].trim()); + if (newExpiryThreshold <= 0) { + throw new SitusException(INVALID_THRESHOLD_MESSAGE); + } + AlertExpiringSoonCommand.setExpiryThreshold(newExpiryThreshold); + return "Successfully set expiry threshold to " + newExpiryThreshold + " days"; case "stock": - AlertLowStockCommand.setLowStockThreshold(Double.parseDouble(details[2].trim())); - return "Successfully set low stock threshold to " + details[2].trim() + " kg"; + double newStockThreshold = Double.parseDouble(details[2].trim()); + if (newStockThreshold <= 0) { + throw new SitusException(INVALID_THRESHOLD_MESSAGE); + } + AlertLowStockCommand.setLowStockThreshold(newStockThreshold); + return "Successfully set low stock threshold to " + newStockThreshold + " kg"; default: - throw new SitusException(INVALID_ALERT_TYPE_MESSAGE); + throw new SitusException(INVALID_THRESHOLD_TYPE_MESSAGE); } } catch (NumberFormatException e) { throw new SitusException(NUMBER_FORMAT_ERROR_MESSAGE);