Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103-F15-2#51 from Hwww23/add_dates
Browse files Browse the repository at this point in the history
Add dates to Student details
  • Loading branch information
zoebelle-pang authored Mar 20, 2024
2 parents 3661284 + 2437d61 commit 84bac19
Show file tree
Hide file tree
Showing 26 changed files with 412 additions and 53 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
This project is an application designed to help tutors efficiently manage students. 👩‍🏫👨‍🏫

### Value Proposition
Provide tutors with access to contact details and schedules of their students.
- Allows the tutor to view the students that they are currently teaching in one glance.
- Allows updating contact details
Provide tutors with access to contact details and schedules of their students.
- Allows the tutor to view the students that they are currently teaching in one glance.
- Allows updating contact details
- Provides easy lookup of students
- Filter contacts by subjects or grade level
- Filter contacts by subjects or grade level
- Shows fee details of student

For the detailed documentation of this project, see [TutorsGo Product Website](https://ay2324s2-cs2103-f15-2.github.io/tp/)

### Acknowledgements
* This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org).

5 changes: 3 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ Format: `help`

Adds a student to the address book.

Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [g/GRADE] [s/SUBJECT] [t/TAG]…​`
Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [g/GRADE] [s/SUBJECT] [d/DATETIME] [t/TAG]…​`

<div markdown="span" class="alert alert-primary">:bulb: **Tip:**
A person can have any number of tags (including 0)
</div>
* Grade should only contain a single letter from A to D, with plus(+), minus(-) or neither.
* DateTime should be in yyyy-mm-dd hhmm

Examples:
* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/B+ s/Mathematics`
* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/B+ s/Mathematics d/2024-02-03 1800`
* `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal`

### Listing all persons : `list`
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public static String format(Person person) {
.append(person.getGrade())
.append("; Subject: ")
.append(person.getSubject())
.append("; Tags: ");
.append("; DateTime: ");
person.getDateTimes().forEach(builder::append);
builder.append("; Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
}
Expand Down
3 changes: 3 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,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;
Expand Down Expand Up @@ -30,6 +31,7 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
Expand All @@ -38,6 +40,7 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_GRADE + "A "
+ PREFIX_SUBJECT + "Mathematics "
+ PREFIX_DATETIME + "2024-03-02 1800"
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
16 changes: 15 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,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;
Expand All @@ -24,6 +25,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
Expand All @@ -49,6 +51,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -107,10 +110,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Grade updatedGrade = personToEdit.getGrade();
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, updatedTags);
updatedGrade, updatedSubject, updatedDateTime, updatedTags);
}

@Override
Expand Down Expand Up @@ -146,6 +150,7 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private Set<DateTime> dateTime;
private Set<Tag> tags;

public EditPersonDescriptor() {}
Expand All @@ -159,6 +164,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
setDateTime(toCopy.dateTime);
setTags(toCopy.tags);
}

Expand Down Expand Up @@ -201,6 +207,14 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setDateTime(Set<DateTime> dateTime) {
this.dateTime = (dateTime != null) ? new HashSet<>(dateTime) : null;
}

public Optional<Set<DateTime>> getDateTime() {
return (dateTime != null) ? Optional.of(Collections.unmodifiableSet(dateTime)) : Optional.empty();
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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_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;
Expand All @@ -15,6 +16,7 @@
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
Expand All @@ -36,7 +38,7 @@ 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_GRADE, PREFIX_SUBJECT, PREFIX_DATETIME);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -57,9 +59,10 @@ public AddCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_SUBJECT).isPresent()) {
subject = ParserUtil.parseSubject(argMultimap.getValue(PREFIX_SUBJECT).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, tagList);
Person student = new Person(name, phone, email, address, grade, subject, 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 @@ -13,4 +13,5 @@ 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_DATETIME = new Prefix("d/");
}
28 changes: 28 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,6 +10,7 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -153,4 +154,31 @@ public static Subject parseSubject(String subject) throws ParseException {
}
return new Subject(trimmedSubject);
}

/**
* Parses a {@code String dateTime} into a {@code dateTime}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code dateTime} is invalid.
*/
public static DateTime parseDateTime(String dateTime) throws ParseException {
requireNonNull(dateTime);
String trimmedDateTime = dateTime.trim();
if (!DateTime.isValidDateTime(trimmedDateTime)) {
throw new ParseException(DateTime.MESSAGE_CONSTRAINTS);
}
return new DateTime(trimmedDateTime);
}

/**
* Parses {@code Collection<String> dateTimes} into a {@code Set<DateTime>}.
*/
public static Set<DateTime> parseDateTimes(Collection<String> dateTimes) throws ParseException {
requireNonNull(dateTimes);
final Set<DateTime> dateTimeSet = new HashSet<>();
for (String dateTime : dateTimes) {
dateTimeSet.add(parseDateTime(dateTime));
}
return dateTimeSet;
}
}
72 changes: 72 additions & 0 deletions src/main/java/seedu/address/model/person/DateTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package seedu.address.model.person;

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

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;

/**
* Represents a dateTime in the address book.
* Guarantees: immutable; dateTime is valid as declared in {@link #isValidDateTime(String)}
*/
public class DateTime {
public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm";
public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}";
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
.withResolverStyle(ResolverStyle.STRICT);

public final String value;

/**
* Constructs a {@code DateTime}.
*
* @param dateTime A valid dateTime.
*/
public DateTime(String dateTime) {
requireNonNull(dateTime);
checkArgument(isValidDateTime(dateTime), MESSAGE_CONSTRAINTS);
this.value = dateTime;
}

public static boolean isValidDateTime(String test) {
return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test);
}

private static boolean isValidDateTimeFormat(String test) {
try {
FORMATTER.parse(test);
return true;
} catch (DateTimeParseException e) {
return false;
}
}

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

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

DateTime otherDateTime = (DateTime) other;
return value.equals(otherDateTime.value);
}

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

/**
* Format state as text for viewing.
*/
public String toString() {
return '[' + value + ']';
}
}
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ public class Person {
private final Address address;
private final Grade grade;
private final Subject subject;
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<Tag> tags) {
requireAllNonNull(name, phone, email, address, grade, subject, tags);
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);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.grade = grade;
this.subject = subject;
this.dateTimes.addAll(dateTimes);
this.tags.addAll(tags);
}

Expand All @@ -64,6 +67,9 @@ public Grade getGrade() {
public Subject getSubject() {
return subject;
}
public Set<DateTime> getDateTimes() {
return Collections.unmodifiableSet(dateTimes);
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
Expand Down Expand Up @@ -106,13 +112,14 @@ public boolean equals(Object other) {
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& dateTimes.equals(otherPerson.dateTimes)
&& tags.equals(otherPerson.tags);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, tags);
return Objects.hash(name, phone, email, address, dateTimes, tags);
}

@Override
Expand All @@ -124,6 +131,7 @@ public String toString() {
.add("address", address)
.add("grade", grade)
.add("subject", subject)
.add("dateTimes", dateTimes)
.add("tags", tags)
.toString();
}
Expand Down
Loading

0 comments on commit 84bac19

Please sign in to comment.