Skip to content

Commit

Permalink
Merge pull request #54 from CSC207-2022F-UofT/feature-7-enrolment-per…
Browse files Browse the repository at this point in the history
…sistence-tests

Feature 7 debugging + feature refinement
  • Loading branch information
jltng authored Dec 5, 2022
2 parents b5e9cf7 + f7d6abd commit 3f503f1
Show file tree
Hide file tree
Showing 41 changed files with 875 additions and 487 deletions.
32 changes: 19 additions & 13 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import screens.*;
import screens.calendar_scheduler.*;
import screens.course_progress.*;
import screens.courses_features.*;
import screens.course_features.*;
import screens.login_registration.*;
import screens.task_management.task_creation_screens.*;
import use_cases.course_features.course_creation_use_case.*;
import use_cases.course_features.course_enrolment_use_case.*;
import use_cases.course_tracker.progress_tracker_use_case.*;
import screens.collaborative_task_scheduling.*;
import use_cases.collaborative_task_scheduling.scheduling_ct_use_case.*;
Expand Down Expand Up @@ -79,16 +80,18 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
ScheduleCTInputBoundary scheduleCTInputBoundary = new ScheduleCTInteractor(scheduleCTOutputBoundary);
ScheduleCTController scheduleCTController = new ScheduleCTController(scheduleCTInputBoundary, TaskMap.getTaskMap(), (StudentUser) user);

CourseCreationDsGateway course;
try {
course = new FileCourse("./src/main/java/data/courses.csv");
} catch (IOException e) {
throw new RuntimeException("Could not create file.");
}
CourseCreationPresenter presenter = new CourseCreationResponseFormatter();
CourseMap courseMap = new CourseMap();
CourseCreationInputBoundary interactor = new CourseCreationInteractor(course, presenter, courseMap);
CourseCreationController courseCreationController = new CourseCreationController(interactor);
// Adding in course creation use case
CourseCreationDsGateway courseCreate = new FileCourse("src/main/java/data/courses.ser");
CourseCreationOutputBoundary coursePresenter = new CourseCreationPresenter();
CourseCreationInputBoundary courseInteractor = new CourseCreationInteractor(courseCreate, coursePresenter);
CourseCreationController courseController = new CourseCreationController(courseInteractor);

// Adding in course enrolment use case
CourseEnrolmentDsGateway enrolCourse = new FileCourse("src/main/java/data/courses.ser");
CourseTasksToStudentTodolistDsGateway tasksToTodolist = new FileUser("src/main/java/data/users.ser");
CourseEnrolmentOutputBoundary enrolmentPresenter = new CourseEnrolmentPresenter();
CourseEnrolmentInputBoundary enrolmentInteractor = new CourseEnrolmentInteractor(enrolCourse, tasksToTodolist, enrolmentPresenter);
CourseEnrolmentController enrolmentController = new CourseEnrolmentController(enrolmentInteractor);

// Build the GUI
StudentChooseTaskCreateScreen chooseStudentTask = new StudentChooseTaskCreateScreen(schedulerPresenter, scheduleConflictPresenter,
Expand All @@ -107,8 +110,11 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
ProgressTrackerScreen progressTrackerScreen = new ProgressTrackerScreen(trackerController);
screens.add("tracker", progressTrackerScreen);

CourseCreationScreen courseCreationScreen = new CourseCreationScreen(courseCreationController, screens, cardLayout);
screens.add("course", courseCreationScreen);
CourseCreationScreen courseCreationScreen = new CourseCreationScreen(courseController, screens, cardLayout);
screens.add("courseCreate", courseCreationScreen);

CourseEnrolmentScreen courseEnrolmentScreen = new CourseEnrolmentScreen(enrolmentController, screens, cardLayout);
screens.add("courseEnrol", courseEnrolmentScreen);

StudentMainScreen studentMainScreen = new StudentMainScreen((StudentUser)user, screens, cardLayout);
screens.add("StudentMain", studentMainScreen);
Expand Down
Binary file added src/main/java/data/TaskMap
Binary file not shown.
Binary file removed src/main/java/data/TaskMap.txt
Binary file not shown.
Binary file removed src/main/java/data/users.ser
Binary file not shown.
44 changes: 28 additions & 16 deletions src/main/java/entities/Course.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package entities;

import java.io.Serializable;
import java.util.ArrayList;

/**
* entity layer
*/

public class Course {
public class Course implements Serializable {
/**
* class for Course entity with private instance variables
* using StudentUser, InstructorUser, and Task entities
Expand All @@ -16,7 +17,8 @@ public class Course {
private String courseID;
private ArrayList<String> students; // stores the IDs of students enrolled in the course
private ArrayList<String> tasks; // stores the IDs of the course's tasks
private Boolean published;
// private Boolean published;
private boolean courseIsValid; // for unit testing

/**
* Creates a new Course with a course name, instructor name, and a list of tasks
Expand All @@ -30,8 +32,8 @@ public Course(String courseName, String courseInstructor, ArrayList<String> task
this.courseInstructor = courseInstructor;
this.courseID = courseName + courseInstructor;
this.tasks = tasks;
this.students = new ArrayList<String>();
this.published = false; // course creation, default set to not yet published
this.students = new ArrayList<>();
// this.published = false; // course creation, default set to not yet published
}

/*
Expand All @@ -48,21 +50,31 @@ public String getCourseID() {
}

public ArrayList<String> getStudents() {
return new ArrayList<String>(this.students);
return new ArrayList<>(this.students);
}
/* add a new student id to the arraylist of student id strings, no return */
public void addStudent(String studentID) {
this.students.add(studentID);
}

/*
arraylist of all the task ids associated with a course
*/
public ArrayList<String> getTasks() {
return new ArrayList<String>(this.tasks);
return new ArrayList<>(this.tasks);
}
public Boolean getPublished() {
return published;
/* new task added to course (input from instructor user) */
public void addTask(String taskID) {
this.tasks.add(taskID);
}

// public Boolean getPublished() {
// return published;
// }
public boolean courseIsValid() {
return !(courseName.equals("") || courseInstructor.equals("") || tasks.isEmpty());
}

/*
setters
don't think any setters are needed...
*/
public void setCourseName(String courseName) {
this.courseName = courseName;
Expand All @@ -74,10 +86,10 @@ public void setCourseID(String courseID) {
this.courseID = courseID;
}
public void setStudents(ArrayList<String> students) {
this.students = new ArrayList<String>(students);
this.students = new ArrayList<>(students);
}
public void setTasks(ArrayList<String> tasks) {
this.tasks = new ArrayList<String>(tasks);
this.tasks = new ArrayList<>(tasks);
}

/**
Expand All @@ -87,7 +99,7 @@ public void setTasks(ArrayList<String> tasks) {
public void removeTask(Task task) {
this.tasks.remove(task.getId());
}
public void setPublished(Boolean published) {
this.published = published;
}
// public void setPublished(Boolean published) {
// this.published = published;
// }
}
85 changes: 43 additions & 42 deletions src/main/java/entities/CourseMap.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
package entities;

import java.io.Serializable;
import java.util.HashMap;

/**
* A map of courseID to the Course
*/

public class CourseMap implements Serializable {
private static HashMap<String, Course> courseMap;


/**
* Find a course using its unique ID
* @param id the unique ID of the course
* @return the Course object associated with the ID
*/
public static Course findCourse(String id) {
return courseMap.get(id);
}

/**
* @param id the unique ID of the Course object
* @param course the course associated with Course
* @return if the course has been added
*/
public static boolean addCourse(String id, Course course) {
if (courseMap.containsKey(id)) {
return false;
}
courseMap.put(id, course);
return true;
}

public void save() {

}

public void load() {

}
}
//
//import java.io.Serializable;
//import java.util.HashMap;
//
///**
// * A map of courseID to the Course
// */
//
//public class CourseMap implements Serializable {
// private static HashMap<String, Course> courseMap;
//
//
// /**
// * Find a course using its unique ID
// * @param id the unique ID of the course
// * @return the Course object associated with the ID
// */
// public static Course findCourse(String id) {
// return courseMap.get(id);
// }
//
// /**
// * @param id the unique ID of the Course object
// * @param course the course associated with Course
// * @return if the course has been added
// */
// public static boolean addCourse(String id, Course course) {
// // 2 courses have the same id
// if (courseMap.containsKey(id)) {
// return false;
// }
// courseMap.put(id, course);
// return true;
// }
//
// public void save() {
//
// }
//
// public void load() {
//
// }
//}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

import use_cases.course_features.course_creation_use_case.CourseCreationInputBoundary;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;
Expand All @@ -19,5 +19,4 @@ CourseCreationResponseModel create(String courseName, String courseInstructor,

return courseInput.create(requestModel);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

public class CourseCreationFailed extends RuntimeException {
public CourseCreationFailed(String error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package screens.courses_features;
package screens.course_features;

// Interface adapters layer

import use_cases.course_features.course_creation_use_case.CourseCreationPresenter;
import use_cases.course_features.course_creation_use_case.CourseCreationOutputBoundary;
import use_cases.course_features.course_creation_use_case.CourseCreationResponseModel;

import javax.swing.*;

public class CourseCreationResponseFormatter implements CourseCreationPresenter {
public class CourseCreationPresenter implements CourseCreationOutputBoundary {

/**
* Alert user to course creation success
* @param response the output from the program
*/
@Override
public CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel response) {

JOptionPane.showMessageDialog(null, "New course created!");
return response;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

// Framework / Drivers layer

Expand All @@ -9,6 +9,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CourseCreationScreen extends JPanel implements ActionListener {
/** the course name chosen by InstructorUser */
Expand All @@ -18,7 +20,7 @@ public class CourseCreationScreen extends JPanel implements ActionListener {
JTextField courseInstructor = new JTextField(15);

/** title of task */
JTextField taskName = new JTextField(15);
JTextField taskNames = new JTextField(15);

/** the controller */
CourseCreationController courseCreationController;
Expand Down Expand Up @@ -47,12 +49,7 @@ public CourseCreationScreen(CourseCreationController controller, JPanel screens,
LabelTextPanel courseInstructorInfo = new LabelTextPanel(
new JLabel("Enter instructor name"), courseInstructor);
LabelTextPanel taskNameInfo = new LabelTextPanel(
new JLabel("Enter task title"), taskName);

// to do:
// need the option to input more than one task at a time
// can just separate by commas (ie. user enters -- task 1, task 2, task 3)
// or can have a '+' button that creates a new text panel for a new task
new JLabel("Enter task title(s), separated by a comma"), taskNames);

// buttons
JButton cancel = new JButton("Cancel");
Expand All @@ -77,20 +74,31 @@ public CourseCreationScreen(CourseCreationController controller, JPanel screens,

/**
* React to a button click which triggers the corresponding use case
* have to keep try catch, or else error messages won't show up
* NEED TO FIX THIS!!!
* 1. loop through tasks + append
*/
@Override
public void actionPerformed(ActionEvent evt) {
// instructor decides to cancel the course creation process
if (evt.getActionCommand().equals("Cancel")) {
screenLayout.show(screens, "StudentMain");
screenLayout.show(screens, "InstructorMain");
} else if (evt.getActionCommand().equals("Save")) {
try {
// initialize new Arraylist and add task
ArrayList<String> tasks = new ArrayList<>();
tasks.add(taskName.getText());
// tasksNames right now is an arraylist of ONE string with the string being "task1, task2"
// split string so that each task is a string
String[] tasksSplit = taskNames.getText().split(",");
List<String> taskArrayList;
taskArrayList = Arrays.asList(tasksSplit);

// tasklist should be arraylist ["task1", "task2"]
// add all strings to arraylist 'tasks'
ArrayList<String> tasks = new ArrayList<>(taskArrayList);

courseCreationController.create(courseName.getText(), courseInstructor.getText(),
tasks);
JOptionPane.showMessageDialog(this, "Course successful created.");
JOptionPane.showMessageDialog(
this, "Course" + courseName.getText() + "and tasks" + tasks + "successfully created.");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentInputBoundary;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentRequestModel;
Expand All @@ -10,11 +10,10 @@ public CourseEnrolmentController(CourseEnrolmentInputBoundary enrolmentGateway)
this.enrolmentInput = enrolmentGateway;
}

CourseEnrolmentResponseModel create(String courseID, String instructorID, String studentID) {
CourseEnrolmentResponseModel enrol(String courseID, String instructorID, String studentID) {
CourseEnrolmentRequestModel requestModel = new CourseEnrolmentRequestModel(
courseID, instructorID, studentID);

return enrolmentInput.create(requestModel);
return enrolmentInput.enrol(requestModel);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package screens.courses_features;
package screens.course_features;

public class CourseEnrolmentFailed extends RuntimeException {
public CourseEnrolmentFailed(String error) {
Expand Down
Loading

0 comments on commit 3f503f1

Please sign in to comment.