Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs #297

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Examples:

### Adding a Tutee: `addTutee`

Adds a Tutee to VolunTier.
Adds a tutee to VolunTier.

Format: `addTutee \n NAME \p PHONE_NUMBER \e EMAIL \a ADDRESS [\h HOURS] [\s SUBJECT]…​`

Expand Down Expand Up @@ -216,7 +216,7 @@ Format: `addTutee \n NAME \p PHONE_NUMBER \e EMAIL \a ADDRESS [\h HOURS] [\s SUB

### Adding a Lesson: `addLesson`

Add a lesson in VolunTier between a tutor and tutee. A lesson must have a tutor, a tutee and a subject.
Adds a lesson in VolunTier between a tutor and tutee. A lesson must have a tutor, a tutee and a subject.

Format: `addLesson TUTOR_INDEX TUTEE_INDEX \s SUBJECT`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ViewCommand extends Command {
public static final String COMMAND_WORD = "view";

public static final String MESSAGE_SUCCESS = "Here is the details of the person you wanted to see: \n %1$s";
public static final String MESSAGE_SUCCESS = "Here are the details of the person you wanted to see: \n %1$s";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Views the person identified by the index number "
+ "used in the displayed person list.\n"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class Name {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should only contain alphanumeric characters and spaces, and it should not be blank.";

/*
* The first character of the address must not be a whitespace,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Phone {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be 8 digits long and start with 6, 8 or 9";
"Phone numbers should only contain numbers, and it should be 8 digits long and start with 6, 8 or 9.";
public static final String VALIDATION_REGEX = "^[689]\\d{7}$";
public final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;

import javafx.collections.ObservableList;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.lesson.Lesson;
import seedu.address.model.person.Person;
import seedu.address.model.person.Subject;
import seedu.address.model.person.Tutee;
import seedu.address.model.person.Tutor;

Expand All @@ -29,6 +31,9 @@ class JsonSerializableAddressBook {

public static final String MESSAGE_DUPLICATE_LESSON = "Lessons list contains duplicate lesson(s).";

public static final String MESSAGE_PERSON_LESSON_MISMATCH = "Lessons list contains some lessons with "
+ "invalid subjects.";

private final List<JsonAdaptedPerson> persons = new ArrayList<>();

private final List<JsonAdaptedLesson> lessons = new ArrayList<>();
Expand Down Expand Up @@ -72,6 +77,23 @@ public JsonSerializableAddressBook(ReadOnlyAddressBook source) {
);
}

public boolean validateLessonSubject(AddressBook addressBook) {
ObservableList<Lesson> lessonList = addressBook.getLessonList();
for (Lesson lesson : lessonList) {
Subject subject = lesson.getSubject();
Tutor tutor = lesson.getTutor();
Tutee tutee = lesson.getTutee();
if (tutor == null || tutee == null) {
return false;
}

if (!tutor.getSubjects().contains(subject) || !tutee.getSubjects().contains(subject)) {
return false;
}
}
return true;
}

/**
* Converts this address book into the model's {@code AddressBook} object.
*
Expand All @@ -96,6 +118,9 @@ public AddressBook toModelType() throws IllegalValueException {
}
addressBook.addLesson(lesson);
}
if (!validateLessonSubject(addressBook)) {
throw new IllegalValueException(MESSAGE_PERSON_LESSON_MISMATCH);
}
return addressBook;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"persons": [
{
"id": 6,
"name": "Lily Seow",
"phone": "98476978",
"email": "[email protected]",
"address": "Blk 480 Tampines Street 72, #14-35, 876922",
"hours": "0",
"subjects": [
"English",
"Science"
],
"role": "Tutee"
},
{
"id": 7,
"name": "Sophia Yeo",
"phone": "90913712",
"email": "[email protected]",
"address": "Blk 589 Ang Mo Kio Street, #18-37, 714536",
"hours": "0",
"subjects": [
"English",
"Math"
],
"role": "Tutor"
}
],
"lessons": [
{
"tutorId": 7,
"tuteeId": 6,
"subject": "Math"
}
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class JsonSerializableAddressBookTest {
private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json");
private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json");
private static final Path DUPLICATE_LESSONS_FILE = TEST_DATA_FOLDER.resolve("duplicateLessonAddressBook.json");
private static final Path PERSON_LESSON_MISMATCH_FILE = TEST_DATA_FOLDER.resolve("personLessonMismatchAddres"
+ "sBook.json");

@Test
public void toModelType_typicalPersonsFile_success() throws Exception {
Expand Down Expand Up @@ -53,4 +55,13 @@ public void toModelType_duplicateLessons_throwsIllegalValueException() throws Ex
assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_LESSON,
dataFromFile::toModelType);
}

@Test
public void toModelType_personLessonMismatch_throwsIllegalValueException() throws Exception {
JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(PERSON_LESSON_MISMATCH_FILE,
JsonSerializableAddressBook.class).get();
assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_PERSON_LESSON_MISMATCH,
dataFromFile::toModelType);
}
}