Skip to content

Commit

Permalink
Merge pull request #167 from muhammad-khair/branch-implement-bidirect…
Browse files Browse the repository at this point in the history
…ional-link

Implement bidirectional link
  • Loading branch information
eezj35 committed Oct 21, 2021
2 parents 261df04 + 404bb8a commit a9085d5
Show file tree
Hide file tree
Showing 28 changed files with 188 additions and 242 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: page
title: Developer Guide
---

This document provides the relevant information for developers-as-users and developers-as-maintainers to learn more about the design architecture and user-related considerations made in designing this application.
This document provides the relevant information for developers-as-users and developers-as-maintainers to learn more about the design architecture and user-related considerations made in designing this application.

To learn more about the design, you can explore the 'Design' section for the implementations and schematics. The 'Requirements' section in the Appendix explains on the relevant user stories, use cases and non-functional requirements taken into consideration. The 'Instructions for manual testing' section at the end of the Appendix shows the relevant manual tests one can perform as a sanity check.

Expand Down
8 changes: 4 additions & 4 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ Example(s):

Displays the student roster of a specified lesson in the student panel.

Command Format: `roster INDEX`
Command Format: `roster LESSON_INDEX`

* Displays the student roster of the lesson of the specified `INDEX`.
* Displays the student roster of the lesson of the specified `LESSON_INDEX`.
* The index refers to the index number shown in the displayed lesson list.
* The index **must be a positive integer** 1, 2, 3, …
* The index **must be a positive integer** `1`, `2`, `3`, …

Examples:
* `roster 1` will display the students currently enrolled in the lesson indexed at `1` in the student panel.
Expand Down Expand Up @@ -300,7 +300,7 @@ Action | Format, Examples
**Unenroll** | `unenroll STUDENT_INDEX l/LESSON_INDEX`<br> e.g. `unenroll 1 l/1`
**Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g. `find James Jake`
**Filter** | `filter [g/GRADE] s[SUBJECT]`<br> e.g. `filter g/P2`
**View roster** | `roster INDEX` <br> e.g. `roster 1`
**View roster** | `roster LESSON_INDEX` <br> e.g. `roster 1`
**List** | `list`
**Help** | `help`
**Exit** | `exit`
2 changes: 1 addition & 1 deletion docs/diagrams/DeleteSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ deactivate TuitioneParser
LogicManager -> DeleteCommand : execute()
activate DeleteCommand

DeleteCommand -> Model : deletePerson(1)
DeleteCommand -> Model : deleteStudent(1)
activate Model

Model --> DeleteCommand
Expand Down
Binary file modified docs/images/DeveloperGuideImage/DeleteSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.tuitione.commons.core.index.Index;
import seedu.tuitione.logic.commands.exceptions.CommandException;
import seedu.tuitione.model.Model;
import seedu.tuitione.model.lesson.Lesson;
import seedu.tuitione.model.student.Student;

/**
Expand All @@ -34,13 +35,19 @@ public DeleteCommand(Index targetIndex) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Student> lastShownList = model.getFilteredStudentList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Student studentToDelete = lastShownList.get(targetIndex.getZeroBased());
List<Lesson> lessonsToUnenroll = studentToDelete.getLessons();
while (!lessonsToUnenroll.isEmpty()) {
Lesson l = lessonsToUnenroll.get(0);
l.unenrollStudent(studentToDelete);
model.setLesson(l, l);
}
model.deleteStudent(studentToDelete);

return new CommandResult(String.format(MESSAGE_DELETE_STUDENT_SUCCESS, studentToDelete));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package seedu.tuitione.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_LESSONS;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.util.List;

Expand Down Expand Up @@ -37,22 +35,19 @@ public DeleteLessonCommand(Index targetIndex) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Lesson> lastShownList = model.getFilteredLessonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_LESSON_DISPLAYED_INDEX);
}
Lesson lessonToDelete = lastShownList.get(targetIndex.getZeroBased());

List<Student> students = lessonToDelete.getStudents();
students.forEach(s -> {
Lesson lessonToDelete = lastShownList.get(targetIndex.getZeroBased());
List<Student> studentsToUnenroll = lessonToDelete.getStudents();
while (!studentsToUnenroll.isEmpty()) {
Student s = studentsToUnenroll.get(0);
s.unenrollFromLesson(lessonToDelete);
model.setStudent(s, s);
}); // remove student -> lesson code linkages
lessonToDelete.removeAll();

}
model.deleteLesson(lessonToDelete);
model.updateFilteredLessonList(PREDICATE_SHOW_ALL_LESSONS);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);

return new CommandResult(String.format(MESSAGE_DELETE_LESSON_SUCCESS, lessonToDelete));
}

Expand Down
42 changes: 12 additions & 30 deletions src/main/java/seedu/tuitione/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import static seedu.tuitione.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.tuitione.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.tuitione.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_LESSONS;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

Expand All @@ -24,8 +21,6 @@
import seedu.tuitione.logic.commands.exceptions.CommandException;
import seedu.tuitione.model.Model;
import seedu.tuitione.model.lesson.Lesson;
import seedu.tuitione.model.lesson.LessonCode;
import seedu.tuitione.model.lesson.Price;
import seedu.tuitione.model.remark.Remark;
import seedu.tuitione.model.student.Address;
import seedu.tuitione.model.student.Email;
Expand Down Expand Up @@ -88,37 +83,28 @@ public CommandResult execute(Model model) throws CommandException {
}

Student studentToEdit = lastShownList.get(index.getZeroBased());
Set<Lesson> studentLessons = studentToEdit.getLessons();
List<Lesson> studentLessons = studentToEdit.getLessons();
Student editedStudent = createEditedStudent(studentToEdit, editStudentDescriptor);

if (!studentToEdit.isSameStudent(editedStudent) && model.hasStudent(editedStudent)) {
throw new CommandException(MESSAGE_DUPLICATE_STUDENT);
}

if (!editStudentDescriptor.gradeIsEdited) {
Map<LessonCode, Price> lessonsCurrentlyTaken = studentToEdit.getLessonCodesAndPrices();
editedStudent.setLessonCodesAndPrices(lessonsCurrentlyTaken);

for (Lesson lesson : studentLessons) {
Lesson lessonClone = lesson.createClone();
lessonClone.removeStudent(studentToEdit);
lessonClone.addStudentNoConstraint(editedStudent); // editedStudent will be able to enroll
model.setLesson(lesson, lessonClone);
editedStudent.addLesson(lessonClone);
}
}

if (editStudentDescriptor.gradeIsEdited) {
while (!studentLessons.isEmpty()) {
Lesson lesson = studentLessons.get(0);
lesson.unenrollStudent(studentToEdit);
model.setLesson(lesson, lesson);
}
} else {
// grade is not modified, hence must be updated in lessons
for (Lesson lesson : studentLessons) {
Lesson lessonClone = lesson.createClone();
lessonClone.removeStudent(studentToEdit);
model.setLesson(lesson, lessonClone);
lesson.updateStudent(studentToEdit, editedStudent);
model.setLesson(lesson, lesson);
}
}

model.setStudent(studentToEdit, editedStudent);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
model.updateFilteredLessonList(PREDICATE_SHOW_ALL_LESSONS);
return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent));
}

Expand All @@ -136,12 +122,8 @@ private static Student createEditedStudent(Student studentToEdit, EditStudentDes
Grade updatedGrade = editStudentDescriptor.getGrade().orElse(studentToEdit.getGrade());
Set<Remark> updatedRemarks = editStudentDescriptor.getRemarks().orElse(studentToEdit.getRemarks());

return new Student(updatedName,
updatedParentContact,
updatedEmail,
updatedAddress,
updatedGrade,
updatedRemarks);
return new Student(updatedName, updatedParentContact, updatedEmail, updatedAddress,
updatedGrade, updatedRemarks);
}

@Override
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/seedu/tuitione/logic/commands/EnrollCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static java.util.Objects.requireNonNull;
import static seedu.tuitione.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.tuitione.logic.parser.CliSyntax.PREFIX_LESSON;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_LESSONS;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.util.List;

Expand Down Expand Up @@ -56,28 +54,23 @@ public CommandResult execute(Model model) throws CommandException {
}
Student studentToEnroll = lastShownList.get(indexStudent.getZeroBased());

if (indexLesson.getZeroBased() >= lastShownList.size()) {
if (indexLesson.getZeroBased() >= lessonList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_LESSON_DISPLAYED_INDEX);
}

Lesson lesson = lessonList.get(indexLesson.getZeroBased());
Lesson newLesson = lesson.createClone();

if (newLesson.containsStudent(studentToEnroll)) {
throw new CommandException(String.format(MESSAGE_STUDENT_IN_LESSON, studentToEnroll.getName(), newLesson));
if (lesson.containsStudent(studentToEnroll)) {
throw new CommandException(String.format(MESSAGE_STUDENT_IN_LESSON, studentToEnroll.getName(), lesson));
}
if (!newLesson.isAbleToEnroll(studentToEnroll)) {
throw new CommandException(String.format(MESSAGE_UNABLE_TO_ENROLL, studentToEnroll.getName(), newLesson));
if (!lesson.isAbleToEnroll(studentToEnroll)) {
throw new CommandException(String.format(MESSAGE_UNABLE_TO_ENROLL, studentToEnroll.getName(), lesson));
}

Student newStudent = studentToEnroll.createClone();
newLesson.addStudent(newStudent);
model.setLesson(lesson, newLesson);
model.setStudent(studentToEnroll, newStudent);
model.updateFilteredLessonList(PREDICATE_SHOW_ALL_LESSONS);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
lesson.enrollStudent(studentToEnroll);
model.setLesson(lesson, lesson);
model.setStudent(studentToEnroll, studentToEnroll);

return new CommandResult(String.format(MESSAGE_SUCCESS, newStudent.getName(), lesson));
return new CommandResult(String.format(MESSAGE_SUCCESS, studentToEnroll.getName(), lesson));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ListCommand extends Command {

public static final String MESSAGE_SUCCESS = "Listed all students & all lessons";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/seedu/tuitione/logic/commands/UnenrollCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static java.util.Objects.requireNonNull;
import static seedu.tuitione.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.tuitione.logic.parser.CliSyntax.PREFIX_LESSON;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_LESSONS;
import static seedu.tuitione.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.util.List;

Expand Down Expand Up @@ -49,8 +47,8 @@ public UnenrollCommand(Index indexStudent, Index indexLesson) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

List<Student> lastShownStudentList = model.getFilteredStudentList();

ObservableList<Lesson> lastShownLessonList = model.getFilteredLessonList();
if (indexStudent.getZeroBased() >= lastShownStudentList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
Expand All @@ -61,24 +59,19 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(Messages.MESSAGE_INVALID_LESSON_DISPLAYED_INDEX);
}
Lesson lesson = lastShownLessonList.get(indexLesson.getZeroBased());
Lesson newLesson = lesson.createClone();

if (!newLesson.containsStudent(studentToUnenroll)) {
if (!lesson.containsStudent(studentToUnenroll)) {
throw new CommandException(String.format(MESSAGE_STUDENT_NOT_IN_LESSON,
studentToUnenroll.getName(),
newLesson));
lesson));
}
lesson.unenrollStudent(studentToUnenroll);

Student newStudent = studentToUnenroll.createClone();

newLesson.removeStudent(newStudent);
model.setStudent(studentToUnenroll, newStudent);
model.setLesson(lesson, newLesson);

model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
model.updateFilteredLessonList(PREDICATE_SHOW_ALL_LESSONS);
model.setStudent(studentToUnenroll, studentToUnenroll);
model.setLesson(lesson, lesson);

return new CommandResult(String.format(MESSAGE_UNENROLL_STUDENT_SUCCESS, newStudent.getName(), newLesson));
return new CommandResult(String.format(MESSAGE_UNENROLL_STUDENT_SUCCESS,
studentToUnenroll.getName(), lesson));
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/tuitione/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public boolean hasStudent(Student student) {
@Override
public void deleteStudent(Student target) {
tuitione.removeStudent(target);
updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
}

@Override
Expand All @@ -114,8 +115,8 @@ public void addStudent(Student student) {
@Override
public void setStudent(Student target, Student editedStudent) {
requireAllNonNull(target, editedStudent);

tuitione.setStudent(target, editedStudent);
updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
}

@Override
Expand All @@ -140,6 +141,7 @@ public void addLesson(Lesson lesson) {
public void setLesson(Lesson target, Lesson editedLesson) {
requireAllNonNull(target, editedLesson);
tuitione.setLesson(target, editedLesson);
updateFilteredLessonList(PREDICATE_SHOW_ALL_LESSONS);
}

//=========== Filtered Student and Lesson List Accessors ======================================================
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/tuitione/model/Tuitione.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void addStudent(Student p) {
*/
public void setStudent(Student target, Student editedStudent) {
requireNonNull(editedStudent);

students.setStudent(target, editedStudent);
}

Expand Down
Loading

0 comments on commit a9085d5

Please sign in to comment.