diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 6d10264d804..247729a2e07 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -105,6 +105,9 @@ private static Student createEditedStudent(Student studentToEdit, EditStudentDes Remark updatedRemark = studentToEdit.getRemark(); FeeStatus updatedFeeStatus = studentToEdit.getFeeStatus(); Subject updatedSubject = editStudentDescriptor.getSubject().orElse(studentToEdit.getSubject()); + for (Lesson lesson : updatedLessons) { + lesson.setSubject(updatedSubject); + } return new Student(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedSubject, updatedRemark, updatedFeeStatus, updatedLessons); diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 2c4cd03a3fc..56ccfe5894b 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -10,6 +10,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT; +import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -58,7 +59,7 @@ public AddCommand parse(String args) throws ParseException { Subject subject = ParserUtil.parseSubject(argMultimap.getValue(PREFIX_SUBJECT).get()); Remark remark = new Remark(argMultimap.getValue(PREFIX_REMARK).orElse("")); // default value FeeStatus feeStatus = new FeeStatus(argMultimap.getValue(PREFIX_FEESTATUS).orElse("")); - List lessonList = ParserUtil.parseLessons((argMultimap.getAllValues(PREFIX_LESSON))); + List lessonList = new ArrayList<>(); Student student = new Student(name, phone, email, address, subject, remark, feeStatus, lessonList); return new AddCommand(student); diff --git a/src/main/java/seedu/address/model/UserPrefs.java b/src/main/java/seedu/address/model/UserPrefs.java index 6be655fb4c7..b618f77a41b 100644 --- a/src/main/java/seedu/address/model/UserPrefs.java +++ b/src/main/java/seedu/address/model/UserPrefs.java @@ -14,7 +14,7 @@ public class UserPrefs implements ReadOnlyUserPrefs { private GuiSettings guiSettings = new GuiSettings(); - private Path addressBookFilePath = Paths.get("data" , "addressbook.json"); + private Path addressBookFilePath = Paths.get("data" , "tutortrack.json"); /** * Creates a {@code UserPrefs} with default values. diff --git a/src/main/java/seedu/address/model/student/Lesson.java b/src/main/java/seedu/address/model/student/Lesson.java index 3fad49d34a7..b54420e20d0 100644 --- a/src/main/java/seedu/address/model/student/Lesson.java +++ b/src/main/java/seedu/address/model/student/Lesson.java @@ -21,9 +21,7 @@ public class Lesson { public static final String TIME_REGEX = "\\d{2}:\\d{2}"; public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yyyy"); public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm"); - private String value; - private String jsonValue; - private final Subject subject; + private Subject subject; private final LocalDate date; private final LocalTime time; private int isCompleted; @@ -45,8 +43,6 @@ public Lesson(String subject, LocalDate date, LocalTime time) { this.date = LocalDate.parse(date.format(DATE_FORMATTER), DATE_FORMATTER); this.time = time; this.isCompleted = 0; - // UI displayed form of lesson - this.value = this.subject + " " + this.date.format(DATE_FORMATTER) + " " + this.time.format(TIME_FORMATTER); } /** @@ -120,22 +116,43 @@ public LocalTime getTime() { public int getLessonStatus() { return isCompleted; } - + /** + * Gets the value of the lesson. + * + * @return The value. + */ public String getLessonValue() { - return value; + return this.subject + " " + this.date.format(DATE_FORMATTER) + " " + this.time.format(TIME_FORMATTER); } + /** + * Gets the json value of the lesson. + * + * @return The json value. + */ public String getJsonValue() { return this.subject.value + "|" + this.date.format(DATE_FORMATTER) + "|" + this.time.format(TIME_FORMATTER) + "|" + this.isCompleted; } - + /** + * Sets the lesson as complete. + */ public void setLessonComplete() { this.isCompleted = 1; } - + /** + * Sets the lesson as incomplete. + */ public void setLessonIncomplete() { this.isCompleted = 0; } + /** + * Sets the new subject of the lesson. + * + * @param subject The subject. + */ + public void setSubject(Subject subject) { + this.subject = subject; + } @Override public boolean equals(Object other) { @@ -149,12 +166,12 @@ public boolean equals(Object other) { } Lesson otherLesson = (Lesson) other; - return value.equals(otherLesson.value); + return getLessonValue().equals(otherLesson.getLessonValue()); } @Override public int hashCode() { - return value.hashCode(); + return getLessonValue().hashCode(); } /** diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalStudentAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalStudentAddressBook.json index de9751880ec..e86400d4dac 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalStudentAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalStudentAddressBook.json @@ -8,7 +8,7 @@ "subject" : "Maths", "remark" : "She likes aardvarks.", "feeStatus": "", - "lessons" : [ "Maths|10-05-2004|12:29|1", "Physics|11-05-2004|12:29|0" ] + "lessons" : [ "Maths|10-05-2004|12:29|1", "Maths|11-05-2004|12:29|0" ] }, { "name" : "Benson Meier", "phone" : "98765432", @@ -35,7 +35,7 @@ "subject" : "History", "remark" : "", "feeStatus": "", - "lessons" : [ "Geography|10-05-2004|12:29|0" ] + "lessons" : [ "History|10-05-2004|12:29|0" ] }, { "name" : "Elle Meyer", "phone" : "9482224", @@ -44,7 +44,7 @@ "subject" : "Psychology", "remark" : "", "feeStatus": "", - "lessons" : [ "Geography|10-05-2004|12:29|1" ] + "lessons" : [ "Psychology|10-05-2004|12:29|1" ] }, { "name" : "Fiona Kunz", "phone" : "9482427", diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 71298814ceb..2e303dd8f8b 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_LESSON_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; @@ -56,11 +55,10 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { Student lastStudent = model.getFilteredStudentList().get(indexLastStudent.getZeroBased()); StudentBuilder studentInList = new StudentBuilder(lastStudent); - Student editedStudent = studentInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) - .withLessons(VALID_LESSON_BOB).build(); + Student editedStudent = studentInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB).build(); EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB) - .withPhone(VALID_PHONE_BOB).withLessons(VALID_LESSON_BOB).build(); + .withPhone(VALID_PHONE_BOB).build(); EditCommand editCommand = new EditCommand(indexLastStudent, descriptor); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_STUDENT_SUCCESS, diff --git a/src/test/java/seedu/address/testutil/TypicalStudents.java b/src/test/java/seedu/address/testutil/TypicalStudents.java index c4ec111681b..409d103db58 100644 --- a/src/test/java/seedu/address/testutil/TypicalStudents.java +++ b/src/test/java/seedu/address/testutil/TypicalStudents.java @@ -32,7 +32,7 @@ public class TypicalStudents { .withSubject("Maths") .withRemark("She likes aardvarks.") .withFeeStatus("Paid.") - .withLessons("Maths|10-05-2004|12:29|1", "Physics|11-05-2004|12:29|0") + .withLessons("Maths|10-05-2004|12:29|1", "Maths|11-05-2004|12:29|0") .build(); public static final Student BENSON = new StudentBuilder().withName("Benson Meier") .withAddress("311, Clementi Ave 2, #02-25") @@ -45,10 +45,10 @@ public class TypicalStudents { .withSubject("English").withLessons("English|10-05-2004|12:29|0") .withEmail("heinz@example.com").withAddress("wall street").build(); public static final Student DANIEL = new StudentBuilder().withName("Daniel Meier").withPhone("87652533") - .withSubject("History").withLessons("Geography|10-05-2004|12:29|0") + .withSubject("History").withLessons("History|10-05-2004|12:29|0") .withEmail("cornelia@example.com").withAddress("10th street").build(); public static final Student ELLE = new StudentBuilder().withName("Elle Meyer").withPhone("9482224") - .withSubject("Psychology").withLessons("Geography|10-05-2004|12:29|1") + .withSubject("Psychology").withLessons("Psychology|10-05-2004|12:29|1") .withEmail("werner@example.com").withAddress("michegan ave").build(); public static final Student FIONA = new StudentBuilder().withName("Fiona Kunz").withPhone("9482427") .withSubject("English").withLessons("English|10-05-2004|12:29|0") @@ -59,10 +59,10 @@ public class TypicalStudents { // Manually added public static final Student HOON = new StudentBuilder().withName("Hoon Meier").withPhone("8482424") - .withSubject("Music").withLessons("Science|10-05-2004|12:29|1") + .withSubject("Music").withLessons("Music|10-05-2004|12:29|1") .withEmail("stefan@example.com").withAddress("little india").build(); public static final Student IDA = new StudentBuilder().withName("Ida Mueller").withPhone("8482131") - .withSubject("Dance").withLessons("Maths|10-06-2004|12:29|0") + .withSubject("Dance").withLessons("Dance|10-06-2004|12:29|0") .withEmail("hans@example.com").withAddress("chicago ave").build(); // Manually added - Student's details found in {@code CommandTestUtil}