diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 707b19d..6f72b20 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -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.*; @@ -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); @@ -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 diff --git a/src/main/java/data/courses.csv b/src/main/java/data/courses.csv deleted file mode 100644 index 122444c..0000000 --- a/src/main/java/data/courses.csv +++ /dev/null @@ -1 +0,0 @@ -course_name,course_instructor,tasks? diff --git a/src/main/java/screens/InstructorMainScreen.java b/src/main/java/screens/InstructorMainScreen.java index a553aa3..6bf69d3 100644 --- a/src/main/java/screens/InstructorMainScreen.java +++ b/src/main/java/screens/InstructorMainScreen.java @@ -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) { diff --git a/src/main/java/screens/StudentMainScreen.java b/src/main/java/screens/StudentMainScreen.java index deed5da..6a0cc22 100644 --- a/src/main/java/screens/StudentMainScreen.java +++ b/src/main/java/screens/StudentMainScreen.java @@ -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"); diff --git a/src/main/java/screens/course_features/FileCourse.java b/src/main/java/screens/course_features/FileCourse.java index 370b2a8..97437cb 100644 --- a/src/main/java/screens/course_features/FileCourse.java +++ b/src/main/java/screens/course_features/FileCourse.java @@ -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; @@ -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: @@ -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(); } } @@ -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(); } /** @@ -93,10 +88,10 @@ 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 @@ -104,6 +99,7 @@ public Map<String, Course> getCourses() { * 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); } @@ -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 } \ No newline at end of file diff --git a/src/main/java/screens/course_features/InMemoryCourse.java b/src/main/java/screens/course_features/InMemoryCourse.java index 6c93ec4..9667e94 100644 --- a/src/main/java/screens/course_features/InMemoryCourse.java +++ b/src/main/java/screens/course_features/InMemoryCourse.java @@ -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; @@ -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() { @@ -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 */ @@ -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); @@ -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); } } diff --git a/src/main/java/screens/login_registration/FileUser.java b/src/main/java/screens/login_registration/FileUser.java index b8b7cf2..1e2a237 100644 --- a/src/main/java/screens/login_registration/FileUser.java +++ b/src/main/java/screens/login_registration/FileUser.java @@ -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; @@ -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; @@ -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 @@ -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 } } diff --git a/src/main/java/screens/task_management/FileTaskMap.java b/src/main/java/screens/task_management/FileTaskMap.java index 746ec13..971d42e 100644 --- a/src/main/java/screens/task_management/FileTaskMap.java +++ b/src/main/java/screens/task_management/FileTaskMap.java @@ -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) { @@ -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); + } } diff --git a/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationDsGateway.java b/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationDsGateway.java index f7b5d1f..568437f 100644 --- a/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationDsGateway.java +++ b/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationDsGateway.java @@ -15,5 +15,5 @@ public interface CourseCreationDsGateway { boolean existsByCourseID(String courseIdentifier); - void saveCourse(Course requestModel) throws IOException; + void save(Course requestModel) throws IOException; } diff --git a/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationInteractor.java b/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationInteractor.java index 71df195..504371e 100644 --- a/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationInteractor.java +++ b/src/main/java/use_cases/course_features/course_creation_use_case/CourseCreationInteractor.java @@ -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); } diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentCourseDsGateway.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentCourseDsGateway.java new file mode 100644 index 0000000..cdf1b04 --- /dev/null +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentCourseDsGateway.java @@ -0,0 +1,25 @@ +package use_cases.course_features.course_enrolment_use_case; + +// Use case layer + +import entities.Course; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * Gateway containing the following methods (override in FileCourse) + * * NOTE: THIS INVOLVES ONLY METHODS REQUIRING ACCESS TO FILECOURSE + * * existsByCourseID: need to check if the course student wants to enrol in actually exists + * * existsByStudent: checks if student username exists in the course's 'students' parameter + * * searchForCourse: find the course object associated with the course id if it exists + * * saveStudentToCourse: takes student username and appends it to the Course's 'students' parameter + * * getCourseTasks: the course's 'tasks' parameter; a list of task id strings + */ +public interface CourseEnrolmentCourseDsGateway { + boolean existsByCourseID(String courseIdentifier); // exact same name as CourseCreationDsGateway + Course searchForCourse(String courseIdentifier); + boolean existsStudentInCourse(String courseID, String studentIdentifier); + void saveStudentToCourse(String studentID, String courseID) throws IOException; // need to update data + ArrayList<String> getCourseTasks(String courseIdentifier); +} diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentDsGateway.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentDsGateway.java index eb1275e..41a80c3 100644 --- a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentDsGateway.java +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentDsGateway.java @@ -1,26 +1,26 @@ -package use_cases.course_features.course_enrolment_use_case; - -// Use case layer - -import entities.Course; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * Gateway containing the following methods (override in FileCourse) - * NOTE: THIS INVOLVES ONLY METHODS REQUIRING ACCESS TO FILECOURSE - * existsByCourseID: need to check if the course student wants to enrol in actually exists - * existsByStudent: checks if student username exists in the course's 'students' parameter - * searchForCourse: find the course object associated with the course id if it exists - * saveStudentToCourse: takes student username and appends it to the Course's 'students' parameter - * courseTasks: the course's 'tasks' parameter; a list of task id strings - */ -public interface CourseEnrolmentDsGateway { - boolean existsByCourseID(String courseIdentifier); // exact same name as CourseCreationDsGateway - public Course searchForCourse(String courseIdentifier); - boolean existsStudentInCourse(String courseID, String studentIdentifier); - void saveStudentToCourse(String studentID, String courseID) throws IOException; - public ArrayList<String> courseTasks(Course requestModel); - -} +//package use_cases.course_features.course_enrolment_use_case; +// +//// Use case layer +// +//import entities.Course; +// +//import java.io.IOException; +//import java.util.ArrayList; +// +///** +// * Gateway containing the following methods (override in FileCourse) +// * NOTE: THIS INVOLVES ONLY METHODS REQUIRING ACCESS TO FILECOURSE +// * existsByCourseID: need to check if the course student wants to enrol in actually exists +// * existsByStudent: checks if student username exists in the course's 'students' parameter +// * searchForCourse: find the course object associated with the course id if it exists +// * saveStudentToCourse: takes student username and appends it to the Course's 'students' parameter +// * courseTasks: the course's 'tasks' parameter; a list of task id strings +// */ +//public interface CourseEnrolmentDsGateway { +// boolean existsByCourseID(String courseIdentifier); // exact same name as CourseCreationDsGateway +// public Course searchForCourse(String courseIdentifier); +// boolean existsStudentInCourse(String courseID, String studentIdentifier); +// void saveStudentToCourse(String studentID, String courseID) throws IOException; +// public ArrayList<String> courseTasks(Course requestModel); +// +//} diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractor.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractor.java index adb53f3..1f2d4f7 100644 --- a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractor.java +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractor.java @@ -3,153 +3,132 @@ // Use case layer import entities.*; -import screens.login_registration.FileUser; -import use_cases.login_registration.user_register_usecase.UserRegGateway; import java.io.IOException; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; -import java.util.Map; public class CourseEnrolmentInteractor implements CourseEnrolmentInputBoundary { - - final CourseEnrolmentDsGateway courseEnrolmentDsGateway; // the course -// final UserRegGateway userRegGateway; // the student - final CourseTasksToStudentTodolistDsGateway tasksToTodolistDsGateway; - final CourseEnrolmentOutputBoundary courseEnrolmentOutputBoundary; // the presenter + final CourseEnrolmentUserDsGateway userDsGateway; + final CourseEnrolmentCourseDsGateway courseDsGateway; + final CourseEnrolmentTaskDsGateway taskDsGateway; + final CourseEnrolmentOutputBoundary enrolmentOutputBoundary; private StudentUser student; // for response model private Course course; // for response model - private Task tasks; // for response model - public CourseEnrolmentInteractor(CourseEnrolmentDsGateway courseEnrolmentDsGateway, - CourseTasksToStudentTodolistDsGateway tasksToDodolistDsGateway, - CourseEnrolmentOutputBoundary courseEnrolmentOutputBoundary) { - this.courseEnrolmentDsGateway = courseEnrolmentDsGateway; - this.tasksToTodolistDsGateway = tasksToDodolistDsGateway; -// this.userRegGateway = userRegGateway; - this.courseEnrolmentOutputBoundary = courseEnrolmentOutputBoundary; + public CourseEnrolmentInteractor(CourseEnrolmentUserDsGateway userDsGateway, + CourseEnrolmentCourseDsGateway courseDsGateway, + CourseEnrolmentTaskDsGateway taskDsGateway, + CourseEnrolmentOutputBoundary enrolmentOutputBoundary) { + this.userDsGateway = userDsGateway; + this.courseDsGateway = courseDsGateway; + this.taskDsGateway = taskDsGateway; + this.enrolmentOutputBoundary = enrolmentOutputBoundary; } - /** - * Creates the task in the request model and returns the corresponding response model - * @param requestModel the input from the student user - */ @Override public CourseEnrolmentResponseModel enrol(CourseEnrolmentRequestModel requestModel) { - // At least one field left blank if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") || requestModel.getStudentID().equals("")) { - return courseEnrolmentOutputBoundary.prepareFailView("Please fill in all required information."); + return enrolmentOutputBoundary.prepareFailView("Please fill in all required information."); } // checks if given course id is in the map of existing courses - if (!courseEnrolmentDsGateway.existsByCourseID(requestModel.getCourseID())) { - return courseEnrolmentOutputBoundary.prepareFailView("Entered information does not correspond to an existing course."); + if (!courseDsGateway.existsByCourseID(requestModel.getCourseID())) { + return enrolmentOutputBoundary.prepareFailView("Entered information does not correspond to an existing course."); } - // checks whether the student is already enrolled in the course - if (courseEnrolmentDsGateway.existsStudentInCourse(requestModel.getCourseID(), requestModel.getStudentID())) { - return courseEnrolmentOutputBoundary.prepareFailView("Already enrolled in course."); - } + // all checks passed; background work for enrolment starts to happen - // checks passed; student can be enrolled + alias of course's tasks created - // no need to import FileCourse because it implements the gateway + // 1. course gateway // add student id to Course parameter 'students' - // saveStudentToCourse methods take care of saving the changes to the file? try { - courseEnrolmentDsGateway.saveStudentToCourse(requestModel.getStudentID(), requestModel.getCourseID()); + courseDsGateway.saveStudentToCourse(requestModel.getStudentID(), requestModel.getCourseID()); } catch (IOException e) { throw new RuntimeException(e); } - // clone course tasks and save to task map (with new student-related ids) - - // tasks should be properly initialized sent to student - - // get course's tasks by creating an alias of the Courses tasks parameter (needs to be referring to the same tasks) -// ArrayList<String> courseTaskTitlesCopy = courseEnrolmentDsGateway.courseTasks(courseEnrolmentDsGateway.searchForCourse(requestModel.getCourseID())); + // get course's task parameter (which takes the task TITLES) + // needed for task gateway step + ArrayList<String> courseTaskTitles = courseDsGateway.getCourseTasks(requestModel.getCourseID()); - /** THIS IS MOVED TO COURSE CREATION USE CASE UNDER GETTASKS METHOD IN REQUEST MODEL BC I AM DUMB*/ -// String tasksOneString = courseTaskTitlesCopy.get(0); -// ArrayList<String> goodCourseTasks = new ArrayList<>(); -// for (String tasksSplit : tasksOneString.split(",")) { -// goodCourseTasks.add(tasksSplit); -// } + // 2. task gateway - // make courseTasks into proper id format: courseTasks_instructor_course, add to an arraylist of Tasks + // transform task titles to actual task ids String instructorName = requestModel.getCourseInstructor(); String courseName = requestModel.getCourseName(); - ArrayList<String> courseTaskTitles = courseEnrolmentDsGateway.courseTasks(courseEnrolmentDsGateway.searchForCourse(requestModel.getCourseID())); - // generates the existing task id from the task title - ArrayList<String> courseTaskId = new ArrayList<>(); + ArrayList<String> courseTaskIDs = new ArrayList<>(); for (String taskTitleToId : courseTaskTitles) { taskTitleToId = taskTitleToId + "_" + instructorName + "_" + courseName; - courseTaskId.add(taskTitleToId); + courseTaskIDs.add(taskTitleToId); } - // find + get taskId-taskValue pairs from TaskMap, save to (temporary) oldTaskIdMap + // for each id in courseTaskIDs, get Task associated with it, save to temp map HashMap<String, Task> oldTaskIdMap = new HashMap<>(); - for (String oldTaskId : courseTaskId) { - Task taskValue = TaskMap.findTask(oldTaskId); // gets value from key + for (String oldTaskId : courseTaskIDs) { + Task taskValue = taskDsGateway.getTask(oldTaskId); // gets value from key oldTaskIdMap.put(oldTaskId, taskValue); // add key-value pair to new map } - // for each taskId-Task pair, change the key name to courseTaskTitle_student_course, add key-value pair to arraylist - HashMap<String, Task> newTaskIdMap = new HashMap<>(); // initialize new TaskIdMap + // create 2 parallel arraylists, one stores task ids, one stores Task objects + ArrayList<String> oldKeys = courseTaskIDs; // could also do (ArrayList) oldTaskIdMap.keySet() - // create 2 parallel arraylists, one for keys, one for values - ArrayList<String> oldKeys = courseTaskId; // could also do (ArrayList) oldTaskIdMap.keySet() - ArrayList<Task> values = (ArrayList) oldTaskIdMap.entrySet(); + // iterate through oldKeys, get corresponding Task object, add to arraylist + ArrayList<Task> values = new ArrayList<>(); + for (String key: oldKeys) { + Task value = oldTaskIdMap.get(key); + values.add(value); + } +// ArrayList<Task> values = (ArrayList<Task>) oldTaskIdMap.entrySet(); + // make newKeys with task id to title_student_course ArrayList<String> newKeys = new ArrayList<>(); // change key name from title_instructor_course to title_student_course - for (String taskId :oldKeys) { + for (String taskId : oldKeys) { // change key name from title_inst_course to title_student_course String newKey = taskId.replace(requestModel.getCourseInstructor(), requestModel.getStudentID()); newKeys.add(newKey); } - // newKeys and values should be of equal length with each index referring to a pair - // ie. newKey[0], values[0] should be the old Task object but with the new course task id name! - - // iterate through one of the arraylists (let's do keys) - for (int i = 0; i <= newKeys.size(); i++) { + // add newKeys and values as a key-value pair to a temp new map + HashMap<String, Task> newTaskIdMap = new HashMap<>(); + for (int i = 0; i < newKeys.size(); i++) { // add key-value pairs to newTaskIdMap newTaskIdMap.put(newKeys.get(i), values.get(i)); } - // add all newTaskIdMap key-value pairs to TaskMap - // TODO: read file, make edits, then save changes - TaskMap.addTasks(newTaskIdMap); + // add newTaskIdMap to FileTaskMap + taskDsGateway.saveNewMaptoMap(newTaskIdMap); + + // 3. user gateway - // add new task ids to the student's to-do list (of task ids) - // need to be initializing Task (check creation interactor) // or maybe not, may not be npe + // add course id to student's 'courses' parameter try { - tasksToTodolistDsGateway.addSaveTasksToTodolist(requestModel.getStudentID(), newKeys); + userDsGateway.addCourseToStudent(requestModel.getCourseID(), requestModel.getStudentID()); } catch (IOException e) { throw new RuntimeException(e); } - // Need to be initializing 'student', but also taken care of ... - // add course to student's 'courses' parameter + // add arraylist newKeys to student's to do list try { - tasksToTodolistDsGateway.addCourseToStudent(requestModel.getCourseID(), requestModel.getStudentID()); + userDsGateway.addTasksToTodolist(requestModel.getStudentID(), newKeys); } catch (IOException e) { throw new RuntimeException(e); } - // need to be initializing 'course' - // create response model, sent to presenter - Course enrolledCourse = new Course( - requestModel.getCourseID(), requestModel.getCourseInstructor(), courseTaskTitles); + // saving changes + // TODO: no need because individual method calls already saves? + + // create response model, send to presenter CourseEnrolmentResponseModel enrolmentResponseModel = new CourseEnrolmentResponseModel( - requestModel.getStudentID(), enrolledCourse.getCourseID(), enrolledCourse.getTasks()); + requestModel.getStudentID(), requestModel.getCourseID(), newKeys); + + return enrolmentOutputBoundary.prepareSuccessView(enrolmentResponseModel); + - return courseEnrolmentOutputBoundary.prepareSuccessView(enrolmentResponseModel); } } diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractorBAD.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractorBAD.java new file mode 100644 index 0000000..4222523 --- /dev/null +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentInteractorBAD.java @@ -0,0 +1,151 @@ +//package use_cases.course_features.course_enrolment_use_case; +// +//// Use case layer +// +//import entities.*; +// +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.HashMap; +// +//public class CourseEnrolmentInteractorBAD implements CourseEnrolmentInputBoundary { +// +// final CourseEnrolmentDsGateway courseEnrolmentDsGateway; // the course +//// final UserRegGateway userRegGateway; // the student +// final CourseTasksToStudentTodolistDsGateway tasksToTodolistDsGateway; +// final CourseEnrolmentOutputBoundary courseEnrolmentOutputBoundary; // the presenter +// private StudentUser student; // for response model +// private Course course; // for response model +// +// private Task tasks; // for response model +// +// public CourseEnrolmentInteractorBAD(CourseEnrolmentDsGateway courseEnrolmentDsGateway, +// CourseTasksToStudentTodolistDsGateway tasksToDodolistDsGateway, +// CourseEnrolmentOutputBoundary courseEnrolmentOutputBoundary) { +// this.courseEnrolmentDsGateway = courseEnrolmentDsGateway; +// this.tasksToTodolistDsGateway = tasksToDodolistDsGateway; +//// this.userRegGateway = userRegGateway; +// this.courseEnrolmentOutputBoundary = courseEnrolmentOutputBoundary; +// } +// +// /** +// * Creates the task in the request model and returns the corresponding response model +// * @param requestModel the input from the student user +// */ +// @Override +// public CourseEnrolmentResponseModel enrol(CourseEnrolmentRequestModel requestModel) { +// +// // At least one field left blank +// if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") +// || requestModel.getStudentID().equals("")) { +// return courseEnrolmentOutputBoundary.prepareFailView("Please fill in all required information."); +// } +// +// // checks if given course id is in the map of existing courses +// if (!courseEnrolmentDsGateway.existsByCourseID(requestModel.getCourseID())) { +// return courseEnrolmentOutputBoundary.prepareFailView("Entered information does not correspond to an existing course."); +// } +// +// // checks whether the student is already enrolled in the course +// if (courseEnrolmentDsGateway.existsStudentInCourse(requestModel.getCourseID(), requestModel.getStudentID())) { +// return courseEnrolmentOutputBoundary.prepareFailView("Already enrolled in course."); +// } +// +// // checks passed; student can be enrolled + alias of course's tasks created +// // no need to import FileCourse because it implements the gateway +// +// // add student id to Course parameter 'students' +// // saveStudentToCourse methods take care of saving the changes to the file? +// try { +// courseEnrolmentDsGateway.saveStudentToCourse(requestModel.getStudentID(), requestModel.getCourseID()); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// +// // clone course tasks and save to task map (with new student-related ids) +// +// // tasks should be properly initialized sent to student +// +// // get course's tasks by creating an alias of the Courses tasks parameter (needs to be referring to the same tasks) +//// ArrayList<String> courseTaskTitlesCopy = courseEnrolmentDsGateway.courseTasks(courseEnrolmentDsGateway.searchForCourse(requestModel.getCourseID())); +// +// /** THIS IS MOVED TO COURSE CREATION USE CASE UNDER GETTASKS METHOD IN REQUEST MODEL BC I AM DUMB*/ +//// String tasksOneString = courseTaskTitlesCopy.get(0); +//// ArrayList<String> goodCourseTasks = new ArrayList<>(); +//// for (String tasksSplit : tasksOneString.split(",")) { +//// goodCourseTasks.add(tasksSplit); +//// } +// +// // make courseTasks into proper id format: courseTasks_instructor_course, add to an arraylist of Tasks +// String instructorName = requestModel.getCourseInstructor(); +// String courseName = requestModel.getCourseName(); +// ArrayList<String> courseTaskTitles = courseEnrolmentDsGateway.courseTasks(courseEnrolmentDsGateway.searchForCourse(requestModel.getCourseID())); +// +// // generates the existing task id from the task title +// ArrayList<String> courseTaskId = new ArrayList<>(); +// for (String taskTitleToId : courseTaskTitles) { +// taskTitleToId = taskTitleToId + "_" + instructorName + "_" + courseName; +// courseTaskId.add(taskTitleToId); +// } +// +// // find + get taskId-taskValue pairs from TaskMap, save to (temporary) oldTaskIdMap +// HashMap<String, Task> oldTaskIdMap = new HashMap<>(); +// for (String oldTaskId : courseTaskId) { +// Task taskValue = TaskMap.findTask(oldTaskId); // gets value from key +// oldTaskIdMap.put(oldTaskId, taskValue); // add key-value pair to new map +// } +// +// // for each taskId-Task pair, change the key name to courseTaskTitle_student_course, add key-value pair to arraylist +// HashMap<String, Task> newTaskIdMap = new HashMap<>(); // initialize new TaskIdMap +// +// // create 2 parallel arraylists, one for keys, one for values +// ArrayList<String> oldKeys = courseTaskId; // could also do (ArrayList) oldTaskIdMap.keySet() +// ArrayList<Task> values = (ArrayList) oldTaskIdMap.entrySet(); +// +// ArrayList<String> newKeys = new ArrayList<>(); +// // change key name from title_instructor_course to title_student_course +// for (String taskId :oldKeys) { +// // change key name from title_inst_course to title_student_course +// String newKey = taskId.replace(requestModel.getCourseInstructor(), requestModel.getStudentID()); +// newKeys.add(newKey); +// } +// +// // newKeys and values should be of equal length with each index referring to a pair +// // ie. newKey[0], values[0] should be the old Task object but with the new course task id name! +// +// // iterate through one of the arraylists (let's do keys) +// for (int i = 0; i <= newKeys.size(); i++) { +// // add key-value pairs to newTaskIdMap +// newTaskIdMap.put(newKeys.get(i), values.get(i)); +// } +// +// // add all newTaskIdMap key-value pairs to TaskMap +// tasksToTodolistDsGateway.add +// TaskMap.addTasks(newTaskIdMap); +// +// // add new task ids to the student's to-do list (of task ids) +// // need to be initializing Task (check creation interactor) // or maybe not, may not be npe +// try { +// tasksToTodolistDsGateway.addSaveTasksToTodolist(requestModel.getStudentID(), newKeys); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// +// // Need to be initializing 'student', but also taken care of ... +// // add course to student's 'courses' parameter +// try { +// tasksToTodolistDsGateway.addCourseToStudent(requestModel.getCourseID(), requestModel.getStudentID()); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// +// // need to be initializing 'course' +// // create response model, sent to presenter +// Course enrolledCourse = new Course( +// requestModel.getCourseID(), requestModel.getCourseInstructor(), courseTaskTitles); +// CourseEnrolmentResponseModel enrolmentResponseModel = new CourseEnrolmentResponseModel( +// requestModel.getStudentID(), enrolledCourse.getCourseID(), enrolledCourse.getTasks()); +// +// return courseEnrolmentOutputBoundary.prepareSuccessView(enrolmentResponseModel); +// } +//} diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentTaskDsGateway.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentTaskDsGateway.java new file mode 100644 index 0000000..a1ff256 --- /dev/null +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentTaskDsGateway.java @@ -0,0 +1,18 @@ +package use_cases.course_features.course_enrolment_use_case; + +import entities.Task; + +import java.util.HashMap; + +/** + * Gateway containing the following methods (override in FileTaskMap) + * NOTE: THIS INVOLVES ONLY METHODS REQUIRING ACCESS TO FILETASKMAP + * getTask: gets the Task object corresponding to its id (key) + * saveNewMaptoMap: puts all contents of a map into filetaskmap + */ +public interface CourseEnrolmentTaskDsGateway { + // get task objects with task id + Task getTask(String taskID); + // put all key-value pairs of a map to the data file + void saveNewMaptoMap(HashMap<String, Task> newMap); +} diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentUserDsGateway.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentUserDsGateway.java new file mode 100644 index 0000000..f5749b6 --- /dev/null +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseEnrolmentUserDsGateway.java @@ -0,0 +1,16 @@ +package use_cases.course_features.course_enrolment_use_case; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * Gateway containing the following methods (override in FileUser) + * NOTE: THIS INVOLVES ONLY METHODS REQUIRING ACCESS TO FILEUSER + * addTasks: locates student object based on id, goes to its + * 'to do list' parameter and appends the arraylist of task ids + */ +public interface CourseEnrolmentUserDsGateway { + + void addCourseToStudent(String courseID, String studentID) throws IOException; + void addTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException; +} diff --git a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseTasksToStudentTodolistDsGateway.java b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseTasksToStudentTodolistDsGateway.java index 6e0fe26..b53b029 100644 --- a/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseTasksToStudentTodolistDsGateway.java +++ b/src/main/java/use_cases/course_features/course_enrolment_use_case/CourseTasksToStudentTodolistDsGateway.java @@ -1,19 +1,27 @@ -package use_cases.course_features.course_enrolment_use_case; - -// Use case layer - -import entities.StudentUser; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * Gateway containing the following methods (override in FileUser) - * addSaveTasksToTodolist: takes tasks with new student username-curated ids - * and appends to Student's 'todolist' parameter - */ -public interface CourseTasksToStudentTodolistDsGateway { -// public StudentUser searchForStudent(String studentIdentifier); - public void addSaveTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException; - public void addCourseToStudent(String studentCourse, String studentID) throws IOException; -} +//package use_cases.course_features.course_enrolment_use_case; +// +//// Use case layer +// +//import entities.StudentUser; +//import entities.Task; +// +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.HashMap; +// +///** +// * Gateway containing the following methods (override in FileUser) +// * addSaveTasksToTodolist: takes tasks with new student username-curated ids +// * and appends to Student's 'todolist' parameter +// */ +//public interface CourseTasksToStudentTodolistDsGateway { +//// public StudentUser searchForStudent(String studentIdentifier); +// public void addNewTaskMap(HashMap<String, Task> newTaskMap); +// +// // get new task map +// +// // update task map (add +// +// public void addSaveTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException; +// public void addCourseToStudent(String studentCourse, String studentID) throws IOException; +//} diff --git a/src/main/java/use_cases/course_tracker/CourseTrackerInteractor.java b/src/main/java/use_cases/course_tracker/CourseTrackerInteractor.java index 32045d3..a90f962 100644 --- a/src/main/java/use_cases/course_tracker/CourseTrackerInteractor.java +++ b/src/main/java/use_cases/course_tracker/CourseTrackerInteractor.java @@ -1,7 +1,7 @@ package use_cases.course_tracker; import entities.*; -import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway; +import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentCourseDsGateway; import java.util.ArrayList; import java.util.HashMap; @@ -36,7 +36,7 @@ protected double stringToDouble(String string) { * @param courseName a String representing the name of the student's course * @return the course ID of the student's course */ - protected String courseNameToID(String courseName, CourseEnrolmentDsGateway courseAccess) { + protected String courseNameToID(String courseName, CourseEnrolmentCourseDsGateway courseAccess) { ArrayList<String> allCourseIDs = ((StudentUser) CurrentUser.getCurrentUser()).getCourses(); diff --git a/src/main/java/use_cases/course_tracker/grade_calculator_use_case/GradeCalculatorInteractor.java b/src/main/java/use_cases/course_tracker/grade_calculator_use_case/GradeCalculatorInteractor.java index f5acd2e..09e3271 100644 --- a/src/main/java/use_cases/course_tracker/grade_calculator_use_case/GradeCalculatorInteractor.java +++ b/src/main/java/use_cases/course_tracker/grade_calculator_use_case/GradeCalculatorInteractor.java @@ -4,7 +4,7 @@ import entities.CurrentUser; import entities.Gradable; import entities.Task; -import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway; +import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentCourseDsGateway; import use_cases.course_tracker.CourseTrackerInteractor; import java.util.ArrayList; @@ -17,12 +17,12 @@ public class GradeCalculatorInteractor extends CourseTrackerInteractor implements GradeCalculatorInputBoundary{ private final GradeCalculatorOutputBoundary presenter; - private final CourseEnrolmentDsGateway courseAccess; + private final CourseEnrolmentCourseDsGateway courseAccess; private final ArrayList<String> targetTasksTitles = new ArrayList<>(); private Double targetCourseGrade; public GradeCalculatorInteractor(GradeCalculatorOutputBoundary presenter, - CourseEnrolmentDsGateway courseAccess) { + CourseEnrolmentCourseDsGateway courseAccess) { this.courseAccess = courseAccess; this.presenter = presenter; } diff --git a/src/main/java/use_cases/course_tracker/progress_tracker_use_case/ProgressTrackerInteractor.java b/src/main/java/use_cases/course_tracker/progress_tracker_use_case/ProgressTrackerInteractor.java index e9c89ec..b6521d9 100644 --- a/src/main/java/use_cases/course_tracker/progress_tracker_use_case/ProgressTrackerInteractor.java +++ b/src/main/java/use_cases/course_tracker/progress_tracker_use_case/ProgressTrackerInteractor.java @@ -1,7 +1,7 @@ package use_cases.course_tracker.progress_tracker_use_case; import entities.*; -import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway; +import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentCourseDsGateway; import use_cases.course_tracker.CourseTrackerInteractor; import java.util.ArrayList; @@ -15,9 +15,9 @@ public class ProgressTrackerInteractor extends CourseTrackerInteractor implements ProgressTrackerInputBoundary{ private final ProgressTrackerOutputBoundary outputBoundary; - private final CourseEnrolmentDsGateway courseAccess; + private final CourseEnrolmentCourseDsGateway courseAccess; public ProgressTrackerInteractor(ProgressTrackerOutputBoundary outputBoundary, - CourseEnrolmentDsGateway courseAccess) { + CourseEnrolmentCourseDsGateway courseAccess) { this.courseAccess = courseAccess; this.outputBoundary = outputBoundary; } diff --git a/src/test/java/test_course_features/CourseEnrolmentDataAccess.java b/src/test/java/test_course_features/CourseEnrolmentDataAccess.java new file mode 100644 index 0000000..60e30a2 --- /dev/null +++ b/src/test/java/test_course_features/CourseEnrolmentDataAccess.java @@ -0,0 +1,56 @@ +//package test_course_features; +// +//import entities.Course; +//import entities.StudentUser; +//import entities.Task; +//import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway; +//import use_cases.course_features.course_enrolment_use_case.CourseTasksToStudentTodolistDsGateway; +// +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.HashMap; +// +//public class CourseEnrolmentDataAccess implements CourseEnrolmentDsGateway { +// private final HashMap<String, Course> courseMap; +// private final HashMap<String, StudentUser> studentMap; +// private final HashMap<String, Task> tasksMap; +// +// public CourseEnrolmentDataAccess(HashMap<String, Course> courseMap, +// HashMap<String, StudentUser> studentMap, +// HashMap<String, Task> tasksMap) { +// this.courseMap = courseMap; +// this.studentMap = studentMap; +// this.tasksMap = tasksMap; +// } +// +// @Override +// public boolean existsByCourseID(String courseIdentifier) { +// return courseMap.containsKey(courseIdentifier); +// } +// @Override +// public Course searchForCourse(String courseIdentifier) { +// return courseMap.get(courseIdentifier); +// } +// @Override +// public boolean existsStudentInCourse(String courseID, String studentIdentifier) { +// return courseMap.get(courseID).getStudents().contains(studentIdentifier); +// } +// @Override +// public void saveStudentToCourse(String studentID, String courseID) throws IOException { +// courseMap.get(courseID).getStudents().add(studentID); +// } +// @Override +// public ArrayList<String> courseTasks(Course requestModel) { +// return requestModel.getTasks(); +// } +// +// /** course tasks to student to do list gateway, too lazy to override */ +// public void addSaveTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException { +// StudentUser username = studentMap.get(studentID); +// username.getToDoList().addAll(courseTasks); +// } +// public void addCourseToStudent(String studentCourse, String studentID) throws IOException { +// StudentUser courseInStudent = studentMap.get(studentID); +// courseInStudent.getCourses().add(studentCourse); +// } +//} diff --git a/src/test/java/test_course_features/CourseEnrolmentInteractorTest.java b/src/test/java/test_course_features/CourseEnrolmentInteractorTest.java index 92e4963..f47af0f 100644 --- a/src/test/java/test_course_features/CourseEnrolmentInteractorTest.java +++ b/src/test/java/test_course_features/CourseEnrolmentInteractorTest.java @@ -1,11 +1,17 @@ package test_course_features; import entities.Course; +import entities.CurrentUser; +import entities.StudentUser; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import screens.course_features.InMemoryCourse; import use_cases.course_features.course_creation_use_case.*; +import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentOutputBoundary; +import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentResponseModel; import java.util.ArrayList; +import java.util.HashMap; import static org.junit.jupiter.api.Assertions.*; @@ -15,5 +21,106 @@ * acc maybe this is why i should be doing tests while i code oop */ public class CourseEnrolmentInteractorTest { + @BeforeAll + static void beforeAll() { +//// CurrentUser.setCurrentUser(new StudentUser("user1", "pwd")); +// StudentUser student = new StudentUser("user1", "pwd"); +// +// ArrayList<String> courseTasks = new ArrayList<>(); +// courseTasks.add("1"); +// courseTasks.add("2"); +// courseTasks.add("3"); +// Course course = new Course("course1", "inst1", courseTasks); +// +// HashMap<String, Course> courseMap = new HashMap<>(); +// courseMap.put("course1", course); +// +// HashMap<String, StudentUser> studentMap = new HashMap<>(); +// studentMap.put("user1", student); +// +// CourseEnrolmentDsGateway enrolmentGateway = new CourseEnrolmentDataAccess(courseMap, studentMap); + } + + @Test + void testing() { + StudentUser student = new StudentUser("user1", "pwd"); + + ArrayList<String> courseTasks = new ArrayList<>(); + courseTasks.add("1"); + courseTasks.add("2"); + courseTasks.add("3"); + Course course = new Course("course1", "inst1", courseTasks); + + HashMap<String, Course> courseMap = new HashMap<>(); + courseMap.put("course1", course); + + HashMap<String, StudentUser> studentMap = new HashMap<>(); + studentMap.put("user1", student); + + CourseEnrolmentOutputBoundary outputBoundary = new CourseEnrolmentOutputBoundary() { + @Override + public CourseEnrolmentResponseModel prepareSuccessView(CourseEnrolmentResponseModel newStudent) { + ArrayList<String> courseTasks1 = new ArrayList<>(); + courseTasks1.add("1"); + courseTasks1.add("2"); + courseTasks1.add("3"); + Course course1 = new Course("course1", "inst1", courseTasks1); + + assertEquals("course1", course1.getCourseID()); + assertEquals("inst1", course1.getCourseName()); + assertEquals("course1inst1", course1.getCourseID()); + assertEquals(courseTasks1, course1.getTasks()); + assertNotNull(course1.getTasks()); +// assertTrue(enrolmentGateway.existsByCourseID(course1.getCourseID())); +// +// assertTrue(enrolmentGateway.searchForCourse(course1.getCourseID())); +// assertTrue(enrolmentGateway.existsStudentInCourse(course1.getCourseID())); +// +// assertTrue(enrolmentGateway.saveStudentToCourse(course1.getCourseID());); + + + // check coursetasks are made into the right ids (name_inst_course) + + // check if the ids are saved to an arraylist + + // check if the values from arraylist get the object associated with it, + // and add to temp map (old task id map) + + // make 2 arraylists, old task ids, Tasks + // check if key name is changed to name_stud_course, and add to new task ids arraylist + + // check if new task map with new id -> Tasks mapping is correct + // + + // check if new task map is in tasksMap + + + + // check + // check if student id is appended to course's 'students' parameter +// assertTrue(enrolmentGateway.searchForCourse("course1").getStudents().contains("user1")); + + // student's to do list contains the course tasks + return null; + } + + @Override + public CourseEnrolmentResponseModel prepareFailView(String error) { + return null; + } + }; + + + } + + @Test + void getCourseTasks() { + + } + + @Test + void addTasksToTodolist() { + + } } diff --git a/src/test/java/test_course_features/course_creation/CourseCreationControllerTest.java b/src/test/java/test_course_features/course_creation/CourseCreationControllerTest.java index 8746f6a..5598b59 100644 --- a/src/test/java/test_course_features/course_creation/CourseCreationControllerTest.java +++ b/src/test/java/test_course_features/course_creation/CourseCreationControllerTest.java @@ -24,7 +24,7 @@ public boolean existsByCourseID(String courseIdentifier) { } @Override - public void saveCourse(Course requestModel) throws IOException { + public void save(Course requestModel) throws IOException { } };