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

Feature 7 course enrolment debugging #83

Merged
merged 7 commits into from
Dec 8, 2022
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
11 changes: 6 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import screens.collaborative_task_scheduling.*;
import use_cases.collaborative_task_scheduling.scheduling_ct_use_case.*;
import use_cases.calendar_scheduler.schedule_conflict_use_case.*;
import use_cases.calendar_scheduler.scheduler_use_case.*;
import use_cases.login_registration.login_usecase.*;
import use_cases.login_registration.logout_usecase.*;
import use_cases.login_registration.user_register_usecase.*;
Expand Down Expand Up @@ -69,7 +68,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio

ScheduleConflictOutputBoundary scheduleConflictOutputBoundary = new ScheduleConflictPresenter();

CourseEnrolmentDsGateway courseAccess = new FileCourse("src/main/java/data/courses.ser");
CourseEnrolmentCourseDsGateway courseAccess = new FileCourse("src/main/java/data/courses.ser");
ProgressTrackerScreen progressTrackerScreen = new ProgressTrackerScreen(screens, cardLayout);
ProgressTrackerOutputBoundary trackerPresenter = new ProgressTrackerPresenter(progressTrackerScreen);
ProgressTrackerInputBoundary trackerInteractor = new ProgressTrackerInteractor(trackerPresenter, courseAccess);
Expand All @@ -91,10 +90,12 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
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");
CourseEnrolmentCourseDsGateway enrolCourse = new FileCourse("src/main/java/data/courses.ser");
CourseEnrolmentUserDsGateway enrolUser = new FileUser("src/main/java/data/users.ser");
CourseEnrolmentTaskDsGateway enrolTasks = new FileTaskMap("src/main/java/data/taskmap.ser");
CourseEnrolmentOutputBoundary enrolmentPresenter = new CourseEnrolmentPresenter();
CourseEnrolmentInputBoundary enrolmentInteractor = new CourseEnrolmentInteractor(enrolCourse, tasksToTodolist, enrolmentPresenter);
CourseEnrolmentInputBoundary enrolmentInteractor = new CourseEnrolmentInteractor(
enrolUser, enrolCourse, enrolTasks, enrolmentPresenter);
CourseEnrolmentController enrolmentController = new CourseEnrolmentController(enrolmentInteractor);

// Adding in logout use case
Expand Down
1 change: 0 additions & 1 deletion src/main/java/data/courses.csv

This file was deleted.

Binary file removed src/main/java/data/users.ser
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/java/entities/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void addStudent(String studentID) {
}

public ArrayList<String> getTasks() {
return new ArrayList<>(this.tasks);
return this.tasks;
// return new ArrayList<>(this.tasks);
}
/* new task added to course (input from instructor user) */
public void addTask(String taskID) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/entities/TaskMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

public class TaskMap implements Serializable {
private static HashMap<String, Task> taskMap;
Expand All @@ -26,6 +27,10 @@ public static void addTask(String id, Task task) {
taskMap.put(id, task);
}

public static void addTasks(Map newTasks) {
taskMap.putAll(newTasks);
}

/**
* Remove a Task from the TaskMap.txt
* @param id - the ID of the Task being removed
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/screens/InstructorMainScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void actionPerformed(ActionEvent evt) {
}

if (evt.getSource() == courses) {
cardLayout.show(screens, "course");
cardLayout.show(screens, "courseCreate");
}

if (evt.getSource() == logout) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/screens/StudentMainScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void actionPerformed(ActionEvent evt) {
cardLayout.show(screens, "tracker");
}
if (evt.getSource() == courses) {
cardLayout.show(screens, "course");
cardLayout.show(screens, "courseEnrol");
}
if (evt.getSource() == scheduleCT) {
cardLayout.show(screens, "scheduleCT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +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(s), separated by a comma"), taskNames);
new JLabel("Enter task title(s), separated by a comma with no space"), taskNames);

// buttons
JButton cancel = new JButton("Cancel");
Expand Down Expand Up @@ -98,7 +98,7 @@ public void actionPerformed(ActionEvent evt) {
courseCreationController.create(courseName.getText(), courseInstructor.getText(),
tasks);
JOptionPane.showMessageDialog(
this, "Course" + courseName.getText() + "and tasks" + tasks + "successfully created.");
this, "Course: " + courseName.getText() + " and tasks: " + tasks + " successfully created.");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Expand Down
60 changes: 25 additions & 35 deletions src/main/java/screens/course_features/FileCourse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import entities.Course;
import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentCourseDsGateway;

import java.io.*;
import java.nio.file.Files;
Expand All @@ -11,7 +11,7 @@
import java.util.HashMap;
import java.util.Map;

public class FileCourse implements CourseCreationDsGateway, CourseEnrolmentDsGateway {
public class FileCourse implements CourseCreationDsGateway, CourseEnrolmentCourseDsGateway {
/**
* is this supposed to be String to Request Model OR String to Course
* for clean architecture:
Expand All @@ -31,11 +31,11 @@ public FileCourse(String path) throws IOException, ClassNotFoundException {
// checks if path or file exists
if (Files.exists(Path.of(path))) {
// exists: read existing file, which is the hashmap of all course ids to course objects
this.courses = readFile();
courses = readFile();
} else {
// dne: create and write empty map to new file
this.courses = new HashMap<>();
saveCourse();
courses = new HashMap<>();
save();
}
}

Expand All @@ -47,39 +47,34 @@ public FileCourse(String path) throws IOException, ClassNotFoundException {
* fileReader.close();
*/
public HashMap<String, Course> readFile() throws IOException, ClassNotFoundException {
HashMap<String, Course> f;
try (FileInputStream fileReader = new FileInputStream(this.filePath)) {
ObjectInputStream in = new ObjectInputStream(fileReader);
f = (HashMap<String, Course>) in.readObject();
in.close();
}
FileInputStream fileReader = new FileInputStream(this.filePath);
ObjectInputStream in = new ObjectInputStream(fileReader);
HashMap<String, Course> f = (HashMap<String, Course>) in.readObject();
in.close();
fileReader.close();
return f;
}

/**
* COURSE CREATION GATEWAY
* adds the request model to database
* @param requestModel the course info that is being saved
*/
@Override
public void saveCourse(Course requestModel) throws IOException {
public void save(Course requestModel) throws IOException {
courses.put(requestModel.getCourseID(), requestModel);
this.saveCourse();
this.save();
}

/**
* COURSE CREATION GATEWAY
* writes the map of course ids to course objects into the Course database file
* after out.close():
* Remove this "close" call; closing the resource is handled automatically by the try-with-resources.
* fileWriter.close();
*/
private void saveCourse() throws IOException {
try (FileOutputStream fileWriter = new FileOutputStream(filePath)) {
ObjectOutputStream out = new ObjectOutputStream(fileWriter);
out.writeObject(courses);
out.close();
}
private void save() throws IOException {
FileOutputStream fileWriter;
fileWriter = new FileOutputStream(filePath);
ObjectOutputStream out = new ObjectOutputStream(fileWriter);
out.writeObject(courses);
out.close();
}

/**
Expand All @@ -93,17 +88,18 @@ public boolean existsByCourseID(String courseIdentifier) {
}

public Map<String, Course> getCourses() {
return this.courses;
return courses;
}

@Override

/**
* COURSE ENROLMENT GATEWAY
* gets the course object associated with course id
* used to add student's id to students parameter
* and to copy the tasks
* @param courseIdentifier the course id of the course that the student wants to enrol in
*/
@Override
public Course searchForCourse(String courseIdentifier) {
return courses.get(courseIdentifier);
}
Expand All @@ -127,23 +123,17 @@ public boolean existsStudentInCourse(String courseID, String studentIdentifier)
@Override
public void saveStudentToCourse(String studentID, String courseID) throws IOException {
courses.get(courseID).getStudents().add(studentID);
saveCourse();

save();
}

/**
* COURSE ENROLMENT GATEWAY
* gets the task ids of the course the student wants to enrol in
* copy and change here as well? or toss to task creation request model
* @param requestModel the course we want tasks from
* @param courseIdentifier the course we want tasks from
*/
@Override
public ArrayList<String> courseTasks(Course requestModel) {
return requestModel.getTasks();
public ArrayList<String> getCourseTasks(String courseIdentifier) {
return courses.get(courseIdentifier).getTasks();
}

// public void add

// add tasks to student's to do list
// sketchy clean architecture happens here
}
27 changes: 20 additions & 7 deletions src/main/java/screens/course_features/InMemoryCourse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

import entities.Course;
import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentCourseDsGateway;


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class InMemoryCourse implements CourseCreationDsGateway, CourseEnrolmentDsGateway {
private Map<String, Course> courses;
/**
* gateway for testing purposes
*/
public class InMemoryCourse implements CourseCreationDsGateway, CourseEnrolmentCourseDsGateway {
private Map<String, Course> courses = new HashMap<>();

public InMemoryCourse() {
this.courses = new HashMap<>();
Expand All @@ -27,6 +29,7 @@ public InMemoryCourse(Map<String, Course> courses) {
// populate

/**
* Creation + Enrolment use case
* @param identifier the course's course id
* @return whether the course exists
*/
Expand All @@ -38,11 +41,21 @@ public boolean existsByCourseID(String identifier) {
public Map<String, Course> getCourses() {
return this.courses;
}

/**
* enrolment use case
* @param courseIdentifier -
*/
@Override
public Course searchForCourse(String courseIdentifier) {
return courses.get(courseIdentifier);
}

/**
* enrolment use case
* @param courseID -
* @param studentIdentifier -
*/
@Override
public boolean existsStudentInCourse(String courseID, String studentIdentifier) {
return courses.get(courseID).getStudents().contains(studentIdentifier);
Expand All @@ -54,15 +67,15 @@ public void saveStudentToCourse(String studentID, String courseID) throws IOExce
}

@Override
public ArrayList<String> courseTasks(Course requestModel) {
return requestModel.getTasks();
public ArrayList<String> getCourseTasks(String courseID) {
return courses.get(courseID).getTasks();
}

/**
* @param requestModel the data to save
*/
@Override
public void saveCourse(Course requestModel) {
public void save(Course requestModel) {
courses.put(requestModel.getCourseID(), requestModel);
}
}
31 changes: 18 additions & 13 deletions src/main/java/screens/login_registration/FileUser.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package screens.login_registration;
import entities.Course;
import entities.StudentUser;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseTasksToStudentTodolistDsGateway;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentUserDsGateway;
import use_cases.login_registration.login_usecase.LoginGateway;
import use_cases.login_registration.logout_usecase.LogoutGateway;
import use_cases.login_registration.user_register_usecase.StudentSaveRequest;
Expand All @@ -16,7 +14,7 @@
import java.util.HashMap;
import java.util.Map;

public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway, CourseTasksToStudentTodolistDsGateway {
public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway, CourseEnrolmentUserDsGateway {

// private final HashMap<String, UserRegSaveRequest> accounts;
private static HashMap<String, UserRegSaveRequest> accounts;
Expand Down Expand Up @@ -102,6 +100,7 @@ public Map<String, UserRegSaveRequest> getAccounts() {
return accounts;
}


/**
* For course enrolment use case (course tasks to do list gateway)
* Adds the course tasks to the student's to-do list
Expand All @@ -110,24 +109,30 @@ public Map<String, UserRegSaveRequest> getAccounts() {
* @param courseTasks the course task ids what will be added to the student's 'to do list' parameter
*/
@Override
public void addSaveTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException {
UserRegSaveRequest username = getAccounts().get(studentID);
public void addTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException {
// casting to student save request
((StudentSaveRequest) username).getToDoList().addAll(courseTasks);
this.save(); // saves the file with new changes
((StudentSaveRequest) accounts.get(studentID)).getToDoList().addAll(courseTasks);
save();
// in interactor, update CurrentUser
// make a new StudentSaveRequest with CurrentUser
// call Gateway.save(StudentSaveRequest)
}

/**
* For course enrolment use case (course tasks to do list gateway)
* Adds the course id to the student's 'courses' parameter
* @param studentCourse the course the student enrolled in
* @param courseID the course the student enrolled in
* @param studentID the username of student enrolled
*/
@Override
public void addCourseToStudent(String studentCourse, String studentID) throws IOException {
UserRegSaveRequest courseInStudent = getAccounts().get(studentID);
public void addCourseToStudent(String courseID, String studentID) throws IOException {
// casting to student save request
((StudentSaveRequest) courseInStudent).getCourses().add(studentCourse);
this.save(); // saves the file with new changes
// initialize current
// StudentUser s = accounts.get(studentID);
((StudentSaveRequest) accounts.get(studentID)).getCourses().add(courseID);
save();
// if adding
// StudentUser s = (StudentUser) CurrentUser.getCurrentUser()
// s.addCourse
}
}
Loading