From ad16f2ee88fa3119ad70ad032db828231e1692af Mon Sep 17 00:00:00 2001 From: zoebelle-pang Date: Thu, 4 Apr 2024 12:21:55 +0800 Subject: [PATCH] Fix validation logic in the parser --- .../logic/parser/EditCommandParser.java | 9 +++ .../address/logic/parser/ParserUtil.java | 60 +++++++++---------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index dc1f3b584de..acc4ea142c6 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -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; @@ -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())); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 3c82a174619..2984733cca0 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -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. @@ -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.