Skip to content

Commit

Permalink
Fix validation logic in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
zoebelle-pang committed Apr 4, 2024
1 parent 763fe67 commit ad16f2e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ATTENDANCE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PAYMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -70,6 +72,13 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_GRADE).isPresent()) {
editPersonDescriptor.setGrade(ParserUtil.parseGrade(argMultimap.getValue(PREFIX_GRADE).get()));
}
if (argMultimap.getValue(PREFIX_PAYMENT).isPresent()) {
editPersonDescriptor.setPayment(ParserUtil.parsePayment(argMultimap.getValue(PREFIX_PAYMENT).get()));
}
if (argMultimap.getValue(PREFIX_ATTENDANCE).isPresent()) {
editPersonDescriptor.setAttendance(ParserUtil.parseAttendance(argMultimap.getValue(PREFIX_ATTENDANCE)
.get()));
}
if (argMultimap.getValue(PREFIX_NOTE).isPresent()) {
editPersonDescriptor.setNote(ParserUtil.parseNote(argMultimap.getValue(PREFIX_NOTE).get()));
}
Expand Down
60 changes: 30 additions & 30 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,6 @@ public static Email parseEmail(String email) throws ParseException {
return new Email(trimmedEmail);
}

/**
* Parses a {@code String grade} into an {@code Grade}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code grade} is invalid.
*/
public static Attendance parseAttendance(String attendance) throws ParseException {
requireNonNull(attendance);
String trimmedAttendance = attendance.trim();
if (!Attendance.isValidAttendance(trimmedAttendance)) {
throw new ParseException(Attendance.MESSAGE_CONSTRAINTS);
}
return new Attendance(trimmedAttendance);
}

/**
* Parses a {@code String grade} into an {@code Grade}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code grade} is invalid.
*/
public static Payment parsePayment(String payment) throws ParseException {
requireNonNull(payment);
String trimmedPayment = payment.trim();
if (!Payment.isValidPayment(trimmedPayment)) {
throw new ParseException(Payment.MESSAGE_CONSTRAINTS);
}
return new Payment(trimmedPayment);
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down Expand Up @@ -188,6 +158,36 @@ public static Subject parseSubject(String subject) throws ParseException {
return new Subject(trimmedSubject);
}

/**
* Parses a {@code String attendance} into an {@code Attendance}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code attendance} is invalid.
*/
public static Attendance parseAttendance(String attendance) throws ParseException {
requireNonNull(attendance);
String trimmedAttendance = attendance.trim();
if (!Attendance.isValidAttendance(trimmedAttendance)) {
throw new ParseException(Attendance.MESSAGE_CONSTRAINTS);
}
return new Attendance(trimmedAttendance);
}

/**
* Parses a {@code String payment} into an {@code Payment}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code payment} is invalid.
*/
public static Payment parsePayment(String payment) throws ParseException {
requireNonNull(payment);
String trimmedPayment = payment.trim();
if (!Payment.isValidPayment(trimmedPayment)) {
throw new ParseException(Payment.MESSAGE_CONSTRAINTS);
}
return new Payment(trimmedPayment);
}

/**
* Parses a {@code String note} into an {@code Note}.
* Leading and trailing whitespaces will be trimmed.
Expand Down

0 comments on commit ad16f2e

Please sign in to comment.