Skip to content

Commit

Permalink
MAJOR CHANGES TO ENROLMENT USE CASE (uncessary files commented out, w…
Browse files Browse the repository at this point in the history
…ill delete later after i make sure this actually works)
  • Loading branch information
jltng committed Dec 7, 2022
1 parent d567611 commit 6deb23d
Show file tree
Hide file tree
Showing 23 changed files with 584 additions and 197 deletions.
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.

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
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(); // TODO: not working? might need to initialize students arraylist size is still 0 ...

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
}
21 changes: 16 additions & 5 deletions src/main/java/screens/course_features/InMemoryCourse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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.IOException;
Expand All @@ -15,7 +15,7 @@
/**
* gateway for testing purposes
*/
public class InMemoryCourse implements CourseCreationDsGateway, CourseEnrolmentDsGateway {
public class InMemoryCourse implements CourseCreationDsGateway, CourseEnrolmentCourseDsGateway {
private Map<String, Course> courses = new HashMap<>();

public InMemoryCourse() {
Expand All @@ -29,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 @@ -40,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 @@ -56,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
}
}
23 changes: 22 additions & 1 deletion src/main/java/screens/task_management/FileTaskMap.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package screens.task_management;

import entities.Task;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentTaskDsGateway;
import use_cases.login_registration.user_register_usecase.StudentSaveRequest;
import use_cases.login_registration.user_register_usecase.UserRegSaveRequest;
import use_cases.task_management.read_write.TaskMapGateway;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

public class FileTaskMap implements TaskMapGateway {
public class FileTaskMap implements TaskMapGateway, CourseEnrolmentTaskDsGateway {
String path;
HashMap<String, Task> taskMap = new HashMap<>();
public FileTaskMap(String path) {
Expand Down Expand Up @@ -60,4 +64,21 @@ public HashMap<String, Task> load() {
public boolean existsById(String id) {
return taskMap.containsKey(id);
}

/**
* For Course enrolment use case
* returns the task object based on the task id
* @param taskId the unique id (key) of the task
* @return
*/
@Override
public Task getTask(String taskId) {
return taskMap.get(taskId);
}

@Override
public void saveNewMaptoMap(HashMap<String, Task> newMap) {
taskMap.putAll(newMap);
save(taskMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
public interface CourseCreationDsGateway {
boolean existsByCourseID(String courseIdentifier);

void saveCourse(Course requestModel) throws IOException;
void save(Course requestModel) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CourseCreationResponseModel create(CourseCreationRequestModel requestMode
// create a new course
Course courseModel = new Course(requestModel.getCourseName(), requestModel.getCourseInstructor(), requestModel.getTasks());
try {
courseCreationDSGateway.saveCourse(courseModel);
courseCreationDSGateway.save(courseModel);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Loading

0 comments on commit 6deb23d

Please sign in to comment.