Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoebelle-pang committed Mar 21, 2024
1 parent 17423e2 commit 5632538
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static String format(Person person) {
.append(person.getGrade())
.append("; Subject: ")
.append(person.getSubject())
.append("; Attendance: ")
.append(person.getAttendance())
.append("; Payment: ")
.append(person.getPayment())
.append("; DateTime: ");
person.getDateTimes().forEach(builder::append);
builder.append("; Tags: ");
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import static java.util.Objects.requireNonNull;
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_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 All @@ -31,6 +33,8 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_GRADE + "ATTENDANCE] "
+ "[" + PREFIX_SUBJECT + "PAYMENT] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
Expand All @@ -40,6 +44,8 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_GRADE + "A "
+ PREFIX_SUBJECT + "Mathematics "
+ PREFIX_ATTENDANCE + "Present "
+ PREFIX_PAYMENT + "Paid "
+ PREFIX_DATETIME + "2024-03-02 1800"
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import static java.util.Objects.requireNonNull;
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_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 All @@ -25,10 +27,12 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Attendance;
import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Payment;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Subject;
Expand All @@ -51,6 +55,8 @@ public class EditCommand extends Command {
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_ATTENDANCE + "PAYMENT] "
+ "[" + PREFIX_PAYMENT + "ATTENDANCE] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
Expand Down Expand Up @@ -109,12 +115,14 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Grade updatedGrade = personToEdit.getGrade();
Attendance updatedAttendance = personToEdit.getAttendance();
Payment updatedPayment = personToEdit.getPayment();
Subject updatedSubject = personToEdit.getSubject();
Set<DateTime> updatedDateTime = editPersonDescriptor.getDateTime().orElse(personToEdit.getDateTimes());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
updatedGrade, updatedSubject, updatedDateTime, updatedTags);
updatedGrade, updatedSubject, updatedAttendance, updatedPayment, updatedDateTime, updatedTags);
}

@Override
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

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_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 All @@ -16,10 +18,12 @@
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Attendance;
import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Payment;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Subject;
Expand All @@ -38,15 +42,15 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_DATETIME);
PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_ATTENDANCE, PREFIX_PAYMENT, PREFIX_DATETIME);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_GRADE, PREFIX_SUBJECT);
PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_ATTENDANCE, PREFIX_PAYMENT);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Expand All @@ -59,10 +63,20 @@ public AddCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_SUBJECT).isPresent()) {
subject = ParserUtil.parseSubject(argMultimap.getValue(PREFIX_SUBJECT).get());
}
Attendance attendance = new Attendance();
if (argMultimap.getValue(PREFIX_ATTENDANCE).isPresent()) {
attendance = ParserUtil.parseAttendance(argMultimap.getValue(PREFIX_ATTENDANCE).get());
}

Payment payment = new Payment();
if (argMultimap.getValue(PREFIX_PAYMENT).isPresent()) {
payment = ParserUtil.parsePayment(argMultimap.getValue(PREFIX_PAYMENT).get());
}
Set<DateTime> dateTimeList = ParserUtil.parseDateTimes(argMultimap.getAllValues(PREFIX_DATETIME));
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person student = new Person(name, phone, email, address, grade, subject, dateTimeList, tagList);
Person student = new Person(name, phone, email, address, grade, subject,
attendance, payment, dateTimeList, tagList);

return new AddCommand(student);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public class CliSyntax {
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_GRADE = new Prefix("g/");
public static final Prefix PREFIX_SUBJECT = new Prefix("s/");
public static final Prefix PREFIX_ATTENDANCE = new Prefix("at/");
public static final Prefix PREFIX_PAYMENT = new Prefix("pa/");
public static final Prefix PREFIX_DATETIME = new Prefix("d/");
}
32 changes: 32 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Attendance;
import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Payment;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Subject;
import seedu.address.model.tag.Tag;
Expand Down Expand Up @@ -98,6 +100,36 @@ 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
61 changes: 61 additions & 0 deletions src/main/java/seedu/address/model/person/Attendance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Student's attendance status in the address book.
*
*/
public class Attendance {

public static final String MESSAGE_CONSTRAINTS =
"Attendance should only be 'Present' or 'Absent', and it should not be blank";
public static final String VALIDATION_REGEX = "(?i)(present|absent)";
public final String value;

/**
* Creates an undefined attendance status for the student.
*/
public Attendance() {
value = "-";
}

/**
* Creates an attendance status for a student.
*
* @param status Attendance status ('Present' or 'Absent').
*/
public Attendance(String status) {
requireNonNull(status);
checkArgument(isValidAttendance(status), MESSAGE_CONSTRAINTS);
value = status;
}

/**
* Returns true if a given string is a valid attendance status.
*/
public static boolean isValidAttendance(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof Attendance)) {
return false;
}

Attendance otherAttendance = (Attendance) other;
return value.equalsIgnoreCase(otherAttendance.value);
}
}
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/model/person/Payment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Student's payment status in the address book.
* Guarantees: immutable; is always valid
*/
public class Payment {
public static final String MESSAGE_CONSTRAINTS =
"Payment should only be 'Paid' or 'Not Paid', and it should not be blank";
public static final String VALIDATION_REGEX = "(?i)(paid|not paid)";
public final String value;

/**
* Creates an undefined payment status for the student.
*/
public Payment() {
value = "-";
}

/**
* Creates a payment status for a student.
*
* @param status Payment status ('Paid' or 'Not Paid').
*/
public Payment(String status) {
requireNonNull(status);
checkArgument(isValidPayment(status), MESSAGE_CONSTRAINTS);
value = status;
}

/**
* Returns true if a given string is a valid payment status.
*/
public static boolean isValidPayment(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof Payment)) {
return false;
}

Payment otherPayment = (Payment) other;
return value.equalsIgnoreCase(otherPayment.value);
}
}
17 changes: 15 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ public class Person {
private final Address address;
private final Grade grade;
private final Subject subject;
private final Attendance attendance;
private final Payment payment;
private final Set<DateTime> dateTimes = new HashSet<>();
private final Set<Tag> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject,
Set<DateTime> dateTimes, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, grade, subject, dateTimes, tags);
Attendance attendance, Payment payment, Set<DateTime> dateTimes, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, grade, subject, attendance, payment, dateTimes, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.grade = grade;
this.subject = subject;
this.attendance = attendance;
this.payment = payment;
this.dateTimes.addAll(dateTimes);
this.tags.addAll(tags);
}
Expand Down Expand Up @@ -67,6 +71,13 @@ public Grade getGrade() {
public Subject getSubject() {
return subject;
}
public Attendance getAttendance() {
return attendance;
}

public Payment getPayment() {
return payment;
}
public Set<DateTime> getDateTimes() {
return Collections.unmodifiableSet(dateTimes);
}
Expand Down Expand Up @@ -131,6 +142,8 @@ public String toString() {
.add("address", address)
.add("grade", grade)
.add("subject", subject)
.add("attendance", attendance)
.add("payment", payment)
.add("dateTimes", dateTimes)
.add("tags", tags)
.toString();
Expand Down
Loading

0 comments on commit 5632538

Please sign in to comment.