Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zoebelle-pang committed Apr 3, 2024
2 parents 971765a + 3bef4e7 commit 0b07c7f
Show file tree
Hide file tree
Showing 27 changed files with 426 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* find the javafx.graphics module, and so the launch is aborted.
*
* By having a separate main class (Main) that doesn't extend Application
* to be the entry point of the application, we avoid this issue.
* to be the entry point of the application, we avoid this issue.RR
*/
public class Main {
private static Logger logger = LogsCenter.getLogger(Main.class);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static String format(Person person) {
.append(person.getAttendance())
.append("; Payment: ")
.append(person.getPayment())
.append("; Note")
.append((person.getNote()))
.append("; DateTime: ");
person.getDateTimes().forEach(builder::append);
builder.append("; Tags: ");
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -33,8 +34,9 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_GRADE + "ATTENDANCE] "
+ "[" + PREFIX_SUBJECT + "PAYMENT] "
+ "[" + PREFIX_ATTENDANCE + "ATTENDANCE] "
+ "[" + PREFIX_PAYMENT + "PAYMENT] "
+ "[" + PREFIX_NOTE + "NOTE] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
Expand All @@ -46,6 +48,7 @@ public class AddCommand extends Command {
+ PREFIX_SUBJECT + "Mathematics "
+ PREFIX_ATTENDANCE + "Present "
+ PREFIX_PAYMENT + "Paid "
+ PREFIX_NOTE + "Sample note "
+ PREFIX_DATETIME + "2024-03-02 1800";

public static final String MESSAGE_SUCCESS = "New Student added: %1$s";
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -32,6 +33,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Note;
import seedu.address.model.person.Payment;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -45,7 +47,7 @@ public class EditCommand extends Command {

public static final String COMMAND_WORD = "edit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the student identified "
+ "by the index number used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
Expand All @@ -57,15 +59,16 @@ public class EditCommand extends Command {
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_ATTENDANCE + "PAYMENT] "
+ "[" + PREFIX_PAYMENT + "ATTENDANCE] "
+ "[" + PREFIX_NOTE + "NOTE] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "johndoe@example.com";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Student: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the address book.";
public static final String MESSAGE_DUPLICATE_DATETIME = "This datetime already exists in the address book";

private final Index index;
Expand Down Expand Up @@ -130,11 +133,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Subject updatedSubject = editPersonDescriptor.getSubject().orElse(personToEdit.getSubject());
Attendance updatedAttendance = editPersonDescriptor.getAttendance().orElse(personToEdit.getAttendance());
Payment updatedPayment = editPersonDescriptor.getPayment().orElse(personToEdit.getPayment());
Note updatedNote = editPersonDescriptor.getNote().orElse(personToEdit.getNote());
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, updatedAttendance, updatedPayment, updatedDateTime, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedGrade, updatedSubject,
updatedAttendance, updatedPayment, updatedNote, updatedDateTime, updatedTags);
}

@Override
Expand Down Expand Up @@ -174,6 +178,7 @@ public static class EditPersonDescriptor {
private Grade grade;
private Attendance attendance;
private Payment payment;
private Note note;
private Set<DateTime> dateTime;
private Set<Tag> tags;

Expand All @@ -190,6 +195,9 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setAddress(toCopy.address);
setSubject(toCopy.subject);
setGrade(toCopy.grade);
setAttendance(toCopy.attendance);
setPayment(toCopy.payment);
setNote(toCopy.note);
setDateTime(toCopy.dateTime);
setTags(toCopy.tags);
}
Expand All @@ -198,7 +206,8 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, subject, grade, dateTime, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, subject, grade, attendance, payment, note,
dateTime, tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -265,6 +274,14 @@ public Optional<Payment> getPayment() {
return Optional.ofNullable(payment);
}

public void setNote(Note note) {
this.note = note;
}

public Optional<Note> getNote() {
return Optional.ofNullable(note);
}

public void setDateTime(Set<DateTime> dateTime) {
this.dateTime = (dateTime != null) ? new HashSet<>(dateTime) : null;
}
Expand Down Expand Up @@ -320,6 +337,7 @@ public String toString() {
.add("grade", grade)
.add("attendance", attendance)
.add("payment", payment)
.add("note", note)
.add("dateTime", dateTime)
.add("tags", tags)
.toString();
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -23,6 +24,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Note;
import seedu.address.model.person.Payment;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -42,15 +44,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_ATTENDANCE, PREFIX_PAYMENT, PREFIX_DATETIME);
PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_ATTENDANCE, PREFIX_PAYMENT, PREFIX_NOTE, 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_ATTENDANCE, PREFIX_PAYMENT);
PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_ATTENDANCE, PREFIX_NOTE, 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 @@ -72,11 +74,15 @@ public AddCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_PAYMENT).isPresent()) {
payment = ParserUtil.parsePayment(argMultimap.getValue(PREFIX_PAYMENT).get());
}
Note note = new Note();
if (argMultimap.getValue(PREFIX_NOTE).isPresent()) {
note = ParserUtil.parseNote(argMultimap.getValue(PREFIX_NOTE).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,
attendance, payment, dateTimeList, tagList);
attendance, payment, note, dateTimeList, tagList);

return new AddCommand(student);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class CliSyntax {
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_NOTE = new Prefix("nt/");
public static final Prefix PREFIX_DATETIME = new Prefix("d/");
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -37,7 +38,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_SUBJECT, PREFIX_GRADE, PREFIX_DATETIME, PREFIX_TAG);
PREFIX_SUBJECT, PREFIX_GRADE, PREFIX_NOTE, PREFIX_DATETIME, PREFIX_TAG);

Index index;

Expand Down Expand Up @@ -69,6 +70,9 @@ 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_NOTE).isPresent()) {
editPersonDescriptor.setNote(ParserUtil.parseNote(argMultimap.getValue(PREFIX_NOTE).get()));
}
parseDateTimeForEdit(argMultimap.getAllValues(PREFIX_DATETIME)).ifPresent(editPersonDescriptor::setDateTime);
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Note;
import seedu.address.model.person.Payment;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Subject;
Expand Down Expand Up @@ -187,6 +188,16 @@ public static Subject parseSubject(String subject) throws ParseException {
return new Subject(trimmedSubject);
}

/**
* Parses a {@code String note} into an {@code Note}.
* Leading and trailing whitespaces will be trimmed.
*/
public static Note parseNote(String note) throws ParseException {
requireNonNull(note);
String trimmedNote = note.trim();
return new Note(trimmedNote);
}

/**
* Parses a {@code String dateTime} into a {@code dateTime}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/seedu/address/model/person/Note.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

/**
* Represents a Student's note in the address book. The note can be empty.
*/
public class Note {
public static final String EMPTY_NOTE_MESSAGE = "<Note is empty. Please use the edit command to modify the note>";
public final String value;

/**
* Creates an undefined note status for the student.
*/
public Note() {
value = EMPTY_NOTE_MESSAGE;
}

/**
* Constructs an {@code Note}.
*
* @param note A student note.
*/
public Note(String note) {
requireNonNull(note);
value = note.isEmpty() ? EMPTY_NOTE_MESSAGE : note;
}

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

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

// instanceof handles nulls
if (!(other instanceof seedu.address.model.person.Note)) {
return false;
}

seedu.address.model.person.Note otherNote = (seedu.address.model.person.Note) other;
return value.equals(otherNote.value);
}

@Override
public int hashCode() {
return value.hashCode();
}

}
12 changes: 10 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ public class Person {
private final Subject subject;
private final Attendance attendance;
private final Payment payment;
private final Note note;
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,
Attendance attendance, Payment payment, Set<DateTime> dateTimes, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, grade, subject, attendance, payment, dateTimes, tags);
Attendance attendance, Payment payment, Note note, Set<DateTime> dateTimes, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, grade, subject, attendance, payment, note, dateTimes, tags);
this.name = name;
this.phone = phone;
this.email = email;
Expand All @@ -45,6 +46,7 @@ public Person(Name name, Phone phone, Email email, Address address, Grade grade,
this.subject = subject;
this.attendance = attendance;
this.payment = payment;
this.note = note;
this.dateTimes.addAll(dateTimes);
this.tags.addAll(tags);
}
Expand Down Expand Up @@ -79,6 +81,11 @@ public Attendance getAttendance() {
public Payment getPayment() {
return payment;
}

public Note getNote() {
return note;
}

public Set<DateTime> getDateTimes() {
return Collections.unmodifiableSet(dateTimes);
}
Expand Down Expand Up @@ -157,6 +164,7 @@ public String toString() {
.add("subject", subject)
.add("attendance", attendance)
.add("payment", payment)
.add("note", note)
.add("dateTimes", dateTimes)
.add("tags", tags)
.toString();
Expand Down
Loading

0 comments on commit 0b07c7f

Please sign in to comment.