Skip to content

Commit

Permalink
Update parsing to handle blank inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kngys committed Nov 7, 2024
1 parent b67cf20 commit 53e83af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class Messages {
public static final String MESSAGE_MUST_BE_PERSON_LIST = "%1$s must only be used in person list view!\n"
+ "Use list command to switch to person list view.";

public static final String MESSAGE_EMPTY_DESCRIPTION = "Description should not be blank!";
public static final String MESSAGE_EMPTY_AMOUNT = "Amount should not be blank!";
public static final String MESSAGE_EMPTY_OTHER_PARTY = "Other party should not be blank!";
public static final String MESSAGE_EMPTY_DATE = "Date should not be blank!";

/**
* Returns an error message indicating the duplicate prefixes.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_EMPTY_AMOUNT;
import static seedu.address.logic.Messages.MESSAGE_EMPTY_DATE;
import static seedu.address.logic.Messages.MESSAGE_EMPTY_DESCRIPTION;
import static seedu.address.logic.Messages.MESSAGE_EMPTY_OTHER_PARTY;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -54,6 +58,8 @@ public AddTransactionCommand parse(String args) throws ParseException {
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_DESCRIPTION, PREFIX_AMOUNT,
PREFIX_OTHER_PARTY, PREFIX_DATE);

verifyNoBlankValues(argMultimap);

String description = argMultimap.getValue(PREFIX_DESCRIPTION).get().trim();
double amount = ParserUtil.parseAmount(argMultimap.getValue(PREFIX_AMOUNT).get().trim());
String otherParty = argMultimap.getValue(PREFIX_OTHER_PARTY).get().trim();
Expand All @@ -72,4 +78,31 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}

/**
* Throws a {@code ParseException} if any of the description, amount, other party and date values are blank.
*/
private static void verifyNoBlankValues(ArgumentMultimap argumentMultimap) throws ParseException {

String description = argumentMultimap.getValue(PREFIX_DESCRIPTION).get().trim();
String amount = argumentMultimap.getValue(PREFIX_AMOUNT).get().trim();
String otherParty = argumentMultimap.getValue(PREFIX_OTHER_PARTY).get().trim();
String date = argumentMultimap.getValue(PREFIX_DATE).get().trim();

if (description.isBlank()) {
throw new ParseException(MESSAGE_EMPTY_DESCRIPTION);
}

if (amount.isBlank()) {
throw new ParseException(MESSAGE_EMPTY_AMOUNT);
}

if (otherParty.isBlank()) {
throw new ParseException(MESSAGE_EMPTY_OTHER_PARTY);
}

if (date.isBlank()) {
throw new ParseException(MESSAGE_EMPTY_DATE);
}
}

}

0 comments on commit 53e83af

Please sign in to comment.