Skip to content

Commit

Permalink
Merge pull request #157 from justinlengch/fix-bug
Browse files Browse the repository at this point in the history
Make UI reflect edited subject for lessons
  • Loading branch information
justinlengch authored Apr 15, 2024
2 parents 20afdc2 + b615a33 commit edf8342
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Lesson> lessonList = ParserUtil.parseLessons((argMultimap.getAllValues(PREFIX_LESSON)));
List<Lesson> lessonList = new ArrayList<>();
Student student = new Student(name, phone, email, address, subject, remark, feeStatus, lessonList);

return new AddCommand(student);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 28 additions & 11 deletions src/main/java/seedu/address/model/student/Lesson.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/seedu/address/testutil/TypicalStudents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -45,10 +45,10 @@ public class TypicalStudents {
.withSubject("English").withLessons("English|10-05-2004|12:29|0")
.withEmail("[email protected]").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("[email protected]").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("[email protected]").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")
Expand All @@ -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("[email protected]").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("[email protected]").withAddress("chicago ave").build();

// Manually added - Student's details found in {@code CommandTestUtil}
Expand Down

0 comments on commit edf8342

Please sign in to comment.