From 7a44a642aa53d148920d5792b69d2c5d806626b6 Mon Sep 17 00:00:00 2001 From: jltng Date: Mon, 14 Nov 2022 12:29:03 -0500 Subject: [PATCH 01/22] course creation skeleton files --- .../courseCreationDSGateway.java | 8 ++++ .../courseCreationDSRequestModel.java | 23 +++++++++++ .../courseCreationInputBoundary.java | 7 ++++ .../courseCreationInteractor.java | 21 ++++++++++ .../courseCreationPresenter.java | 9 ++++ .../courseCreationRequestModel.java | 41 +++++++++++++++++++ .../courseCreationResponseModel.java | 41 +++++++++++++++++++ .../courseCreationUseCase.java | 10 +++++ 8 files changed, 160 insertions(+) create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java create mode 100644 src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java new file mode 100644 index 0000000..98c7c95 --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java @@ -0,0 +1,8 @@ +package course_enrolment_and_creation_usecase; + +public interface courseCreationDSGateway { + boolean existsByCourseName(String courseIdentifier); + boolean existsByInstructorName(String instructorIdentifier); + + void saveCourse(courseCreationRequestModel requestModel); +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java new file mode 100644 index 0000000..d8b834c --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java @@ -0,0 +1,23 @@ +package course_enrolment_and_creation_usecase; + +// Use case layer + +import java.util.ArrayList; + +public class courseCreationDSRequestModel { + private final String courseName; + private final String courseInstructor; + private final ArrayList tasks; + + public courseCreationDSRequestModel(String courseName, String courseInstructor, ArrayList tasks) { + this.courseName = courseName; + this.courseInstructor = courseInstructor; + this.tasks = tasks; + } + + public String getCourseName() { + return courseName; + } + + //// finish up +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java new file mode 100644 index 0000000..2040fde --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java @@ -0,0 +1,7 @@ +package course_enrolment_and_creation_usecase; + +import Entities.Course; + +public interface courseCreationInputBoundary { + courseCreationResponseModel create(courseCreationRequestModel requestModel); +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java new file mode 100644 index 0000000..a58f341 --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java @@ -0,0 +1,21 @@ +package course_enrolment_and_creation_usecase; + +public class courseCreationInteractor implements courseCreationInputBoundary { + final courseCreationDSGateway courseCreationDSGateway; + final courseCreationPresenter courseCreationPresenter; + + public courseCreationInteractor(courseCreationDSGateway courseCreationDSGateway, + courseCreationPresenter courseCreationPresenter) { + this.courseCreationDSGateway = courseCreationDSGateway; + this.courseCreationPresenter = courseCreationPresenter; + } + + @Override + public courseCreationResponseModel create(courseCreationRequestModel requestModel) { + /* + fail: instructor and course match with one in database + success otherwise + */ + return null; + } +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java new file mode 100644 index 0000000..c9f0a81 --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java @@ -0,0 +1,9 @@ +package course_enrolment_and_creation_usecase; + +// Use case layer + +public interface courseCreationPresenter { + courseCreationResponseModel prepareSuccessView(courseCreationResponseModel newCourse); + + courseCreationResponseModel prepareFailView(courseCreationResponseModel error); +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java new file mode 100644 index 0000000..21fe5c7 --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java @@ -0,0 +1,41 @@ +package course_enrolment_and_creation_usecase; + +// Use case layer + +import java.util.ArrayList; + +public class courseCreationRequestModel { + private String courseName; + private String courseInstructor; + private ArrayList tasks; + + public courseCreationRequestModel(String courseName, String courseInstructor, ArrayList tasks) { + this.courseName = courseName; + this.courseInstructor = courseInstructor; + this.tasks = tasks; + } + + String getCourseName() { + return courseName; + } + + void setCourseName() { + this.courseName = courseName; + } + + String getCourseInstructor() { + return courseInstructor; + } + + void setCourseInstructor() { + this.courseInstructor = courseInstructor; + } + + public ArrayList getTasks() { + return tasks; + } + + public void setTasks() { + this.tasks = tasks; + } +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java new file mode 100644 index 0000000..f9f646f --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java @@ -0,0 +1,41 @@ +package course_enrolment_and_creation_usecase; + +import java.util.ArrayList; + +// FIX THIS IS WRONG + +public class courseCreationResponseModel { + String courseName; + String instructorName; + ArrayList tasks; + + public courseCreationResponseModel(String courseName, String instructorName) { + this.courseName = courseName; + this.instructorName = instructorName; + } + + public String getCourseName() { + return this.courseName; + } + + public void setCourseName() { + this.courseName = courseName; + } + + public String getInstructorName() { + return this.instructorName; + } + + public void setInstructorName() { + this.instructorName = instructorName; + } + + public ArrayList getTasks() { + return this.tasks; + } + + public void setTasks() { + this.tasks = tasks; + } +} + diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java new file mode 100644 index 0000000..fc10e17 --- /dev/null +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java @@ -0,0 +1,10 @@ +package course_enrolment_and_creation_usecase; +import Entities.Course; + +public class courseCreationUseCase { + private final Course course; + + public courseCreationUseCase(Course course) { + this.course = course; + } +} From d4be5cf154a2bd2fa146fe76932c4b6376fdb82d Mon Sep 17 00:00:00 2001 From: jltng Date: Wed, 16 Nov 2022 17:54:34 -0500 Subject: [PATCH 02/22] added CourseMap entity, started unit tests, fixed use case files --- build.gradle | 1 + src/main/java/Entities/CourseMap.java | 42 ++++++++++++ .../courseCreationDSGateway.java | 3 +- .../courseCreationDSRequestModel.java | 5 ++ .../courseCreationInteractor.java | 40 +++++++---- .../courseCreationRequestModel.java | 21 +++--- .../courseCreationResponseModel.java | 68 ++++++++++++------- .../CourseCreationInteractorTest.java | 4 ++ test/entities/CourseUnitTest.java | 15 ++++ 9 files changed, 150 insertions(+), 49 deletions(-) create mode 100644 src/main/java/Entities/CourseMap.java create mode 100644 test/course_creation_use_case/CourseCreationInteractorTest.java create mode 100644 test/entities/CourseUnitTest.java diff --git a/build.gradle b/build.gradle index 6a4f51c..8de8038 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,7 @@ repositories { dependencies { implementation 'junit:junit:4.13.1' testImplementation('org.junit.jupiter:junit-jupiter:5.6.0') + testImplementation 'org.testng:testng:7.1.0' } test { diff --git a/src/main/java/Entities/CourseMap.java b/src/main/java/Entities/CourseMap.java new file mode 100644 index 0000000..41453b3 --- /dev/null +++ b/src/main/java/Entities/CourseMap.java @@ -0,0 +1,42 @@ +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 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 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 boolean addCourse(String id, Course course) { + if (courseMap.containsKey(id)) { + return false; + } + courseMap.put(id, course); + return true; + } + + public void save() { + + } + + public void load() { + + } +} diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java index 415e600..8c4126d 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java @@ -5,11 +5,10 @@ // Notes: // ** the methods the repo needs to implement for the interactor to do its job - public interface courseCreationDSGateway { // boolean existsByCourseName(String courseIdentifier); // boolean existsByInstructorName(String instructorIdentifier); boolean existsByCourseID(String courseIdentifier); - void saveCourse(courseCreationRequestModel requestModel); + void saveCourse(courseCreationDSRequestModel requestModel); } diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java index c82af71..b627d99 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java @@ -11,11 +11,13 @@ public class courseCreationDSRequestModel { private final String courseName; private final String courseInstructor; + private final String courseID; private ArrayList tasks; public courseCreationDSRequestModel(String courseName, String courseInstructor, ArrayList tasks) { this.courseName = courseName; this.courseInstructor = courseInstructor; + this.courseID = courseName + courseInstructor; this.tasks = tasks; } @@ -25,6 +27,9 @@ public String getCourseName() { public String getCourseInstructor() { return courseInstructor; } + public String getCourseID() { + return courseID; + } public ArrayList getTasks() { return tasks; } diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java index 803036d..6e3c9aa 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java @@ -4,40 +4,52 @@ // Use case layer -// Notes -// VERY CONFUSED --> NEED COURSE FACTORY? -// ** the class that runs the use case (subclass of input boundary) -// the highest level concept; the most protected +/* Notes +VERY CONFUSED --> NEED COURSE FACTORY? +** the class that runs the use case (subclass of input boundary) +the highest level concept; the most protected + */ public class courseCreationInteractor implements courseCreationInputBoundary { final courseCreationDSGateway courseCreationDSGateway; final courseCreationPresenter courseCreationPresenter; - public courseCreationInteractor(courseCreationDSGateway courseCreationDSGateway, - courseCreationPresenter courseCreationPresenter) { + public courseCreationInteractor(courseCreationDSGateway courseCreationDSGateway, courseCreationPresenter courseCreationPresenter) { this.courseCreationDSGateway = courseCreationDSGateway; this.courseCreationPresenter = courseCreationPresenter; } @Override public courseCreationResponseModel create(courseCreationRequestModel requestModel) { + /* At least one info box left blank */ + if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") || requestModel.getTasks().isEmpty()) { + return courseCreationPresenter.prepareFailView("Please fill in all required information."); + } /* + Note: no need to check if is instructor; users would have different + views because they are in different use cases If the course id (same course name and instructor name) already exists, new course will not be made. - Otherwise pass + Else success */ if (courseCreationDSGateway.existsByCourseID(requestModel.getCourseID())) { return courseCreationPresenter.prepareFailView("Course already exists."); } + return null; -// Course course = courseFactory.create(requestModel.getCourseID(), requestModel.getTasks()); -// courseCreationDSRequestModel courseCreationDSModel -// = new courseCreationDSRequestModel(course.ge) /* - blah blah blah saved to gateway huh - make new ___ in response model - then return success view + * what is a courseFactory and is it needed */ - return null; + +// Course course = courseFactory.create(requestModel.getCourseID(), requestModel.getTasks()); +// +// /* checks passed, course successfully created and saved */ +// courseCreationDSRequestModel courseCreationDSModel = new courseCreationDSRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); +// courseCreationDSGateway.saveCourse(courseCreationDSModel); +// +// /* checks passed, course sent to presenter */ +// courseCreationResponseModel courseResponseModel = new courseCreationResponseModel( +// course.getCourseID(), course.getTasks()); +// return courseCreationPresenter.prepareFailViewSuccessView(courseResponseModel); } } diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java index 7eae1c6..4b92d38 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java @@ -4,7 +4,7 @@ // Notes: // DONE? -// requests what is needed for its input data +// requests what is needed for its input data (what person in front of computer enters) // do NOT depend on anything NOR have any references to Entity objects: violates SRP import java.util.ArrayList; @@ -22,19 +22,21 @@ public courseCreationRequestModel(String courseName, String courseInstructor, Ar this.tasks = tasks; } -// String getCourseName() { -// return courseName; -// } + String getCourseName() { + return courseName; + } + + public void setCourseName() { - void setCourseName() { this.courseName = courseName; } -// String getCourseInstructor() { -// return courseInstructor; -// } + String getCourseInstructor() { + return courseInstructor; + } + + public void setCourseInstructor() { - void setCourseInstructor() { this.courseInstructor = courseInstructor; } @@ -43,6 +45,7 @@ String getCourseID() { } public ArrayList getTasks() { + return tasks; } diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java b/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java index c1b6954..da4d179 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java +++ b/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java @@ -9,37 +9,57 @@ // do NOT depend on anything NOR have any references to Entity objects: violates SRP public class courseCreationResponseModel { - String courseName; - String instructorName; +// String courseName; +// String instructorName; + String courseID; ArrayList tasks; - public courseCreationResponseModel(String courseName, String instructorName) { - this.courseName = courseName; - this.instructorName = instructorName; - } - - public String getCourseName() { - return this.courseName; + public courseCreationResponseModel(String courseID, ArrayList tasks) { + this.courseID = courseID; + this.tasks = tasks; } - - public void setCourseName() { - this.courseName = courseName; + public String getCourseID() { + return courseID; } - - public String getInstructorName() { - return this.instructorName; + public void setCourseID() { + this.courseID = courseID; } - - public void setInstructorName() { - this.instructorName = instructorName; - } - public ArrayList getTasks() { - return this.tasks; + return tasks; } - public void setTasks() { - this.tasks = tasks; - } + // do not think this is needed +// public void setTasks() { +// this.tasks = tasks; +// } + +// public courseCreationResponseModel(String courseName, String instructorName) { +// this.courseName = courseName; +// this.instructorName = instructorName; +// } +// +// public String getCourseName() { +// return this.courseName; +// } +// +// public void setCourseName() { +// this.courseName = courseName; +// } +// +// public String getInstructorName() { +// return this.instructorName; +// } +// +// public void setInstructorName() { +// this.instructorName = instructorName; +// } +// +// public ArrayList getTasks() { +// return this.tasks; +// } +// +// public void setTasks() { +// this.tasks = tasks; +// } } diff --git a/test/course_creation_use_case/CourseCreationInteractorTest.java b/test/course_creation_use_case/CourseCreationInteractorTest.java new file mode 100644 index 0000000..24e2d21 --- /dev/null +++ b/test/course_creation_use_case/CourseCreationInteractorTest.java @@ -0,0 +1,4 @@ +package course_creation_use_case; + +public class CourseCreationInteractorTest { +} diff --git a/test/entities/CourseUnitTest.java b/test/entities/CourseUnitTest.java new file mode 100644 index 0000000..8204028 --- /dev/null +++ b/test/entities/CourseUnitTest.java @@ -0,0 +1,15 @@ +package entities; + +//import org.junit.jupiter.api.Test; +// +//import static org.junit.jupiter.api.Assertions.assertFalse; +// +//public class CourseUnitTest { +// +// @Test +// void givenCourse_whenCourseExists_thenIsFalse() { +// Course course = new Course("csc207", "paulgries", "tasks idk"); +// +// assertFalse(course.courseExists); +// } +//} From 47ea70361d36c956ba37b67073d4617bf3dcce75 Mon Sep 17 00:00:00 2001 From: jltng Date: Thu, 17 Nov 2022 09:20:15 -0500 Subject: [PATCH 03/22] use case layer for course enrolment use case completed with except interactor --- .../courseEnrolmentDsGateway.java | 10 +++++ .../courseEnrolmentDsRequestModel.java | 23 +++++++++++ .../courseEnrolmentInputBoundary.java | 7 ++++ .../courseEnrolmentInteractor.java | 40 +++++++++++++++++++ .../courseEnrolmentPresenter.java | 11 +++++ .../courseEnrolmentRequestModel.java | 35 ++++++++++++++++ .../courseEnrolmentResponseModel.java | 28 +++++++++++++ .../courseEnrolmentUseCase.java | 4 ++ 8 files changed, 158 insertions(+) create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java create mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java b/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java new file mode 100644 index 0000000..eb0454e --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java @@ -0,0 +1,10 @@ +package course_enrolment_use_case; + +// Use case layer + +public interface courseEnrolmentDsGateway { + /* checks if student is in the course */ + boolean existsByStudent(String studentIdentifier); + + void saveStudent(courseEnrolmentDsRequestModel requestModel); +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java b/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java new file mode 100644 index 0000000..28d954d --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java @@ -0,0 +1,23 @@ +package course_enrolment_use_case; + +public class courseEnrolmentDsRequestModel { + private final String courseName; + private final String courseInstructor; + private final String courseID; // searches using this + + public courseEnrolmentDsRequestModel(String courseName, String courseInstructor) { + this.courseName = courseName; + this.courseInstructor = courseInstructor; + this.courseID = courseName + courseInstructor; + } + + public String getCourseName() { + return courseName; + } + public String getCourseInstructor() { + return courseInstructor; + } + public String getCourseID() { + return courseID; + } +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java b/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java new file mode 100644 index 0000000..850dde7 --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java @@ -0,0 +1,7 @@ +package course_enrolment_use_case; + +// Use case layer + +public interface courseEnrolmentInputBoundary { + courseEnrolmentResponseModel create(courseEnrolmentRequestModel requestModel); +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java b/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java new file mode 100644 index 0000000..8056d2b --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java @@ -0,0 +1,40 @@ +package course_enrolment_use_case; + +// Use case layer + +import Entities.CourseMap; + +public class courseEnrolmentInteractor implements courseEnrolmentInputBoundary { + final courseEnrolmentDsGateway courseEnrolmentDsGateway; + final courseEnrolmentPresenter courseEnrolmentPresenter; + + public courseEnrolmentInteractor(courseEnrolmentDsGateway courseEnrolmentDsGateway, courseEnrolmentPresenter courseEnrolmentPresenter) { + this.courseEnrolmentDsGateway = courseEnrolmentDsGateway; + this.courseEnrolmentPresenter = courseEnrolmentPresenter; + } + + @Override + public courseEnrolmentResponseModel create(courseEnrolmentRequestModel requestModel) { + /* At least one info box left blank */ + if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("")) { + return courseEnrolmentPresenter.prepareFailView("Please fill in all required information." ); + /* map is courseid --> Course + * checks if given course id is in the map of existing courses*/ + } +// else if (!CourseMap.containsKey(requestModel.getCourseID())) { +// return courseEnrolmentPresenter.prepareFailView("Entered information does not correspond to an existing course."); +// } + + /* + check whether student is enrolled in course + map is courseid --> Course objects + with valid courseid, go to Course.students and check if it contains STUDENT's id + */ +// if (CourseMap.mapping(requestModel.getCourseID()).contains(courseEnrolmentDsGateway.existsByStudent(requestModel.getStudentID()))) { +// return courseEnrolmentPresenter.prepareFailView("Already enrolled in course."); +// } + + return null; + } + +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java b/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java new file mode 100644 index 0000000..e314707 --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java @@ -0,0 +1,11 @@ +package course_enrolment_use_case; + +// Use case layer + +public interface courseEnrolmentPresenter { + /* when course is found */ + courseEnrolmentResponseModel prepareSuccessView(courseEnrolmentResponseModel newStudent); + + /* when course name and instructor combo not present in database*/ + courseEnrolmentResponseModel prepareFailView(String error); +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java b/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java new file mode 100644 index 0000000..9cd28c0 --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java @@ -0,0 +1,35 @@ +package course_enrolment_use_case; + +// Use case layer + +public class courseEnrolmentRequestModel { + private String courseName; + private String courseInstructor; + private final String courseID; + + public courseEnrolmentRequestModel(String courseName, String courseInstructor) { + this.courseName = courseName; + this.courseInstructor = courseInstructor; + this.courseID = courseName + courseInstructor; + } + + String getCourseName() { + return courseName; + } + + public void setCourseName() { + this.courseName = courseName; + } + + String getCourseInstructor() { + return courseInstructor; + } + + public void setCourseInstructor() { + this.courseInstructor = courseInstructor; + } + + String getCourseID() { + return courseID; + } +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java b/src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java new file mode 100644 index 0000000..6a2334e --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java @@ -0,0 +1,28 @@ +package course_enrolment_use_case; + +import java.util.ArrayList; + +public class courseEnrolmentResponseModel { + String studentID; + ArrayList tasks; // not sure if this goes here + + + /** + * The info that is stored in the database + * The CourseMap will only be storing the IDs of enrolled StudentUsers + * @param studentID the ID corresponding to the StudentUser + * @param tasks the tasks of the course + */ + public courseEnrolmentResponseModel(String studentID, ArrayList tasks) { + this.studentID = studentID; + this.tasks = tasks; + } + + public String getStudentID() { + return studentID; + } + + public ArrayList getTasks() { + return tasks; + } +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java b/src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java new file mode 100644 index 0000000..c688c12 --- /dev/null +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java @@ -0,0 +1,4 @@ +package course_enrolment_use_case; + +public class courseEnrolmentUseCase { +} From 2ccf7a444c710a801c94dc34054abf71d965e411 Mon Sep 17 00:00:00 2001 From: jltng Date: Thu, 17 Nov 2022 12:29:18 -0500 Subject: [PATCH 04/22] use case layer for course enrolment use case completed with except interactor --- src/main/java/Entities/Course.java | 13 ++++++++++ .../courseCreationDSGateway.java | 2 +- .../courseCreationDSRequestModel.java | 2 +- .../courseCreationInputBoundary.java | 2 +- .../courseCreationInteractor.java | 4 +-- .../courseCreationPresenter.java | 2 +- .../courseCreationRequestModel.java | 2 +- .../courseCreationResponseModel.java | 2 +- .../courseCreationUseCase.java | 2 +- test/entities/CourseUnitTest.java | 26 +++++++++---------- 10 files changed, 34 insertions(+), 23 deletions(-) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationDSGateway.java (89%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationDSRequestModel.java (95%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationInputBoundary.java (86%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationInteractor.java (97%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationPresenter.java (88%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationRequestModel.java (96%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationResponseModel.java (97%) rename src/main/java/{course_enrolment_and_creation_usecase => course_creation_use_case}/courseCreationUseCase.java (82%) diff --git a/src/main/java/Entities/Course.java b/src/main/java/Entities/Course.java index 36208fe..a68ec2b 100644 --- a/src/main/java/Entities/Course.java +++ b/src/main/java/Entities/Course.java @@ -13,6 +13,7 @@ public class Course { */ private String courseName; private String courseInstructor; + private String courseID; private ArrayList students; // stores the IDs of students enrolled in the course private ArrayList tasks; // stores the IDs of the course's tasks private Boolean published; @@ -27,6 +28,7 @@ public class Course { public Course(String courseName, String courseInstructor, ArrayList tasks) { this.courseName = courseName; this.courseInstructor = courseInstructor; + this.courseID = courseName + courseInstructor; this.tasks = tasks; this.students = new ArrayList(); this.published = false; // course creation, default set to not yet published @@ -41,9 +43,17 @@ public String getCourseName() { public String getCourseInstructor() { return courseInstructor; } + public String getCourseID() { + return this.courseID; + } + public ArrayList getStudents() { return new ArrayList(this.students); } + + /* + arraylist of all the task ids associated with a course + */ public ArrayList getTasks() { return new ArrayList(this.tasks); } @@ -60,6 +70,9 @@ public void setCourseName(String courseName) { public void setCourseInstructor(String courseInstructor) { this.courseInstructor = courseInstructor; } + public void setCourseID(String courseID) { + this.courseID = courseID; + } public void setStudents(ArrayList students) { this.students = new ArrayList(students); } diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java b/src/main/java/course_creation_use_case/courseCreationDSGateway.java similarity index 89% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java rename to src/main/java/course_creation_use_case/courseCreationDSGateway.java index 8c4126d..5b53992 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSGateway.java +++ b/src/main/java/course_creation_use_case/courseCreationDSGateway.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; // Use case layer diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java b/src/main/java/course_creation_use_case/courseCreationDSRequestModel.java similarity index 95% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java rename to src/main/java/course_creation_use_case/courseCreationDSRequestModel.java index b627d99..11ba2be 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationDSRequestModel.java +++ b/src/main/java/course_creation_use_case/courseCreationDSRequestModel.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; // Use case layer diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java b/src/main/java/course_creation_use_case/courseCreationInputBoundary.java similarity index 86% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java rename to src/main/java/course_creation_use_case/courseCreationInputBoundary.java index 1705011..2931d4c 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInputBoundary.java +++ b/src/main/java/course_creation_use_case/courseCreationInputBoundary.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; // Use case layer diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java b/src/main/java/course_creation_use_case/courseCreationInteractor.java similarity index 97% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java rename to src/main/java/course_creation_use_case/courseCreationInteractor.java index 6e3c9aa..f1a1524 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/courseCreationInteractor.java @@ -1,6 +1,4 @@ -package course_enrolment_and_creation_usecase; - -import Entities.Course; +package course_creation_use_case; // Use case layer diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java b/src/main/java/course_creation_use_case/courseCreationPresenter.java similarity index 88% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java rename to src/main/java/course_creation_use_case/courseCreationPresenter.java index 2f26a2e..5e947ee 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationPresenter.java +++ b/src/main/java/course_creation_use_case/courseCreationPresenter.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; // Use case layer diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java b/src/main/java/course_creation_use_case/courseCreationRequestModel.java similarity index 96% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java rename to src/main/java/course_creation_use_case/courseCreationRequestModel.java index 4b92d38..c7083c0 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationRequestModel.java +++ b/src/main/java/course_creation_use_case/courseCreationRequestModel.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; // Use case layer diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java b/src/main/java/course_creation_use_case/courseCreationResponseModel.java similarity index 97% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java rename to src/main/java/course_creation_use_case/courseCreationResponseModel.java index da4d179..ba796c5 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationResponseModel.java +++ b/src/main/java/course_creation_use_case/courseCreationResponseModel.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; import java.util.ArrayList; diff --git a/src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java b/src/main/java/course_creation_use_case/courseCreationUseCase.java similarity index 82% rename from src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java rename to src/main/java/course_creation_use_case/courseCreationUseCase.java index bad8552..63d02e1 100644 --- a/src/main/java/course_enrolment_and_creation_usecase/courseCreationUseCase.java +++ b/src/main/java/course_creation_use_case/courseCreationUseCase.java @@ -1,4 +1,4 @@ -package course_enrolment_and_creation_usecase; +package course_creation_use_case; import Entities.Course; // Notes: diff --git a/test/entities/CourseUnitTest.java b/test/entities/CourseUnitTest.java index 8204028..1c17df3 100644 --- a/test/entities/CourseUnitTest.java +++ b/test/entities/CourseUnitTest.java @@ -1,15 +1,15 @@ package entities; -//import org.junit.jupiter.api.Test; -// -//import static org.junit.jupiter.api.Assertions.assertFalse; -// -//public class CourseUnitTest { -// -// @Test -// void givenCourse_whenCourseExists_thenIsFalse() { -// Course course = new Course("csc207", "paulgries", "tasks idk"); -// -// assertFalse(course.courseExists); -// } -//} +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class CourseUnitTest { + + @Test + void givenCourse_whenCourseExists_thenIsFalse() { + Course course = new Course("csc207", "paulgries", "tasks idk"); + + assertFalse(course.courseExists); + } +} From 8b5d1c83795279cc5fdad6dc43e1d10233483289 Mon Sep 17 00:00:00 2001 From: jltng Date: Thu, 17 Nov 2022 17:47:22 -0500 Subject: [PATCH 05/22] deleted useCase files --- .../courseCreationUseCase.java | 13 ------------- .../courseEnrolmentUseCase.java | 4 ---- test/entities/CourseUnitTest.java | 3 ++- 3 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 src/main/java/course_creation_use_case/courseCreationUseCase.java delete mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java diff --git a/src/main/java/course_creation_use_case/courseCreationUseCase.java b/src/main/java/course_creation_use_case/courseCreationUseCase.java deleted file mode 100644 index 63d02e1..0000000 --- a/src/main/java/course_creation_use_case/courseCreationUseCase.java +++ /dev/null @@ -1,13 +0,0 @@ -package course_creation_use_case; -import Entities.Course; - -// Notes: -// Is this even needed - -public class courseCreationUseCase { - private final Course course; - - public courseCreationUseCase(Course course) { - this.course = course; - } -} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java b/src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java deleted file mode 100644 index c688c12..0000000 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentUseCase.java +++ /dev/null @@ -1,4 +0,0 @@ -package course_enrolment_use_case; - -public class courseEnrolmentUseCase { -} diff --git a/test/entities/CourseUnitTest.java b/test/entities/CourseUnitTest.java index 1c17df3..25b1a21 100644 --- a/test/entities/CourseUnitTest.java +++ b/test/entities/CourseUnitTest.java @@ -4,11 +4,12 @@ import static org.junit.jupiter.api.Assertions.assertFalse; +import Entities.Course; public class CourseUnitTest { @Test void givenCourse_whenCourseExists_thenIsFalse() { - Course course = new Course("csc207", "paulgries", "tasks idk"); + Course course = new Course("csc207", "abc", "tasks idk"); assertFalse(course.courseExists); } From 9bfa7a73e02aebc1592a8b4353cd50d52044e135 Mon Sep 17 00:00:00 2001 From: jltng Date: Thu, 17 Nov 2022 22:18:37 -0500 Subject: [PATCH 06/22] entity layer - added course factory // screen layer = started screens, controller and main file --- src/main/java/Entities/CourseFactory.java | 11 +++ src/main/java/Main.java | 47 +++++++++++ ...eway.java => courseCreationDsGateway.java} | 4 +- ...java => courseCreationDsRequestModel.java} | 4 +- .../courseCreationInteractor.java | 9 +- .../screens/CourseCreationController.java | 23 +++++ .../java/screens/CourseCreationFailed.java | 7 ++ .../CourseCreationResponseFormatter.java | 20 +++++ src/main/java/screens/CreateCourseScreen.java | 36 ++++++++ src/main/java/screens/FileCourse.java | 83 +++++++++++++++++++ src/main/java/screens/InMemoryCourse.java | 28 +++++++ src/main/java/screens/LabelTextPanel.java | 10 +++ 12 files changed, 276 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Entities/CourseFactory.java create mode 100644 src/main/java/Main.java rename src/main/java/course_creation_use_case/{courseCreationDSGateway.java => courseCreationDsGateway.java} (75%) rename src/main/java/course_creation_use_case/{courseCreationDSRequestModel.java => courseCreationDsRequestModel.java} (88%) create mode 100644 src/main/java/screens/CourseCreationController.java create mode 100644 src/main/java/screens/CourseCreationFailed.java create mode 100644 src/main/java/screens/CourseCreationResponseFormatter.java create mode 100644 src/main/java/screens/CreateCourseScreen.java create mode 100644 src/main/java/screens/FileCourse.java create mode 100644 src/main/java/screens/InMemoryCourse.java create mode 100644 src/main/java/screens/LabelTextPanel.java diff --git a/src/main/java/Entities/CourseFactory.java b/src/main/java/Entities/CourseFactory.java new file mode 100644 index 0000000..7852ca0 --- /dev/null +++ b/src/main/java/Entities/CourseFactory.java @@ -0,0 +1,11 @@ +package Entities; + +// Entity layer + +import java.util.ArrayList; + +public class CourseFactory { + public Course create(String courseName, String courseInstructor, ArrayList tasks) { + return new Course(courseName, courseInstructor, tasks); + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..76047e4 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,47 @@ +import Entities.CourseFactory; +import course_creation_use_case.courseCreationDsGateway; +import course_creation_use_case.courseCreationInputBoundary; +import course_creation_use_case.courseCreationInteractor; +import course_creation_use_case.courseCreationPresenter; +import screens.CourseCreationController; +import screens.CourseCreationResponseFormatter; +import screens.CreateCourseScreen; +import screens.FileCourse; + +import javax.swing.*; +import java.awt.*; +import java.io.IOException; + +public class Main { + public static void main(String[] args) { + + // build main program window + JFrame application = new JFrame("Course Creation Example"); + CardLayout cardLayout = new CardLayout(); + JPanel screens = new JPanel(cardLayout); + application.add(screens); + + // create parts to plug into the use case + entities engine + courseCreationDsGateway course; + try { + course = new FileCourse("./courses.csv"); + } catch (IOException e) { + throw new RuntimeException("Could not create file."); + } + courseCreationPresenter presenter = new CourseCreationResponseFormatter(); + CourseFactory courseFactory = new CourseFactory(); + courseCreationInputBoundary interactor = new courseCreationInteractor( + course, presenter, courseFactory); + CourseCreationController courseCreationController = new CourseCreationController( + interactor + ); + + // build the GUI, plugging in the parts + CreateCourseScreen createCourseScreen = new CreateCourseScreen(courseCreationController); + screens.add(createCourseScreen, "create a new course"); + cardLayout.show(screens, "create course"); + application.pack(); + application.setVisible(true); + + } +} diff --git a/src/main/java/course_creation_use_case/courseCreationDSGateway.java b/src/main/java/course_creation_use_case/courseCreationDsGateway.java similarity index 75% rename from src/main/java/course_creation_use_case/courseCreationDSGateway.java rename to src/main/java/course_creation_use_case/courseCreationDsGateway.java index 5b53992..bb2ebab 100644 --- a/src/main/java/course_creation_use_case/courseCreationDSGateway.java +++ b/src/main/java/course_creation_use_case/courseCreationDsGateway.java @@ -5,10 +5,10 @@ // Notes: // ** the methods the repo needs to implement for the interactor to do its job -public interface courseCreationDSGateway { +public interface courseCreationDsGateway { // boolean existsByCourseName(String courseIdentifier); // boolean existsByInstructorName(String instructorIdentifier); boolean existsByCourseID(String courseIdentifier); - void saveCourse(courseCreationDSRequestModel requestModel); + void saveCourse(courseCreationDsRequestModel requestModel); } diff --git a/src/main/java/course_creation_use_case/courseCreationDSRequestModel.java b/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java similarity index 88% rename from src/main/java/course_creation_use_case/courseCreationDSRequestModel.java rename to src/main/java/course_creation_use_case/courseCreationDsRequestModel.java index 11ba2be..2844c4f 100644 --- a/src/main/java/course_creation_use_case/courseCreationDSRequestModel.java +++ b/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java @@ -8,13 +8,13 @@ import java.util.ArrayList; -public class courseCreationDSRequestModel { +public class courseCreationDsRequestModel { private final String courseName; private final String courseInstructor; private final String courseID; private ArrayList tasks; - public courseCreationDSRequestModel(String courseName, String courseInstructor, ArrayList tasks) { + public courseCreationDsRequestModel(String courseName, String courseInstructor, ArrayList tasks) { this.courseName = courseName; this.courseInstructor = courseInstructor; this.courseID = courseName + courseInstructor; diff --git a/src/main/java/course_creation_use_case/courseCreationInteractor.java b/src/main/java/course_creation_use_case/courseCreationInteractor.java index f1a1524..361cc82 100644 --- a/src/main/java/course_creation_use_case/courseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/courseCreationInteractor.java @@ -8,13 +8,18 @@ the highest level concept; the most protected */ +import Entities.CourseFactory; + public class courseCreationInteractor implements courseCreationInputBoundary { - final courseCreationDSGateway courseCreationDSGateway; + final courseCreationDsGateway courseCreationDSGateway; final courseCreationPresenter courseCreationPresenter; + final CourseFactory courseFactory; - public courseCreationInteractor(courseCreationDSGateway courseCreationDSGateway, courseCreationPresenter courseCreationPresenter) { + public courseCreationInteractor(courseCreationDsGateway courseCreationDSGateway, courseCreationPresenter courseCreationPresenter, + CourseFactory courseFactory) { this.courseCreationDSGateway = courseCreationDSGateway; this.courseCreationPresenter = courseCreationPresenter; + this.courseFactory = courseFactory; } @Override diff --git a/src/main/java/screens/CourseCreationController.java b/src/main/java/screens/CourseCreationController.java new file mode 100644 index 0000000..633d20a --- /dev/null +++ b/src/main/java/screens/CourseCreationController.java @@ -0,0 +1,23 @@ +package screens; + +import course_creation_use_case.courseCreationInputBoundary; +import course_creation_use_case.courseCreationRequestModel; +import course_creation_use_case.courseCreationResponseModel; + +import java.util.ArrayList; + +public class CourseCreationController { + final courseCreationInputBoundary courseInput; + public CourseCreationController(courseCreationInputBoundary courseGateway) { + this.courseInput = courseGateway; + } + + courseCreationResponseModel create(String courseName, String courseInstructor, + ArrayList tasks) { + courseCreationRequestModel requestModel = new courseCreationRequestModel( + courseName, courseInstructor, tasks); + + return courseInput.create(requestModel); + } + +} \ No newline at end of file diff --git a/src/main/java/screens/CourseCreationFailed.java b/src/main/java/screens/CourseCreationFailed.java new file mode 100644 index 0000000..319602a --- /dev/null +++ b/src/main/java/screens/CourseCreationFailed.java @@ -0,0 +1,7 @@ +package screens; + +public class CourseCreationFailed extends RuntimeException { + public CourseCreationFailed(String error) { + super(error); + } +} diff --git a/src/main/java/screens/CourseCreationResponseFormatter.java b/src/main/java/screens/CourseCreationResponseFormatter.java new file mode 100644 index 0000000..6e00fbb --- /dev/null +++ b/src/main/java/screens/CourseCreationResponseFormatter.java @@ -0,0 +1,20 @@ +package screens; + +// Interface adapters layer + +import course_creation_use_case.courseCreationPresenter; +import course_creation_use_case.courseCreationResponseModel; + +public class CourseCreationResponseFormatter implements courseCreationPresenter { + + @Override + public courseCreationResponseModel prepareSuccessView(courseCreationResponseModel response) { + /* not sure what this is lol */ + return response; + } + + @Override + public courseCreationResponseModel prepareFailView(String error) { + throw new CourseCreationFailed(error); + } +} diff --git a/src/main/java/screens/CreateCourseScreen.java b/src/main/java/screens/CreateCourseScreen.java new file mode 100644 index 0000000..37e2d4d --- /dev/null +++ b/src/main/java/screens/CreateCourseScreen.java @@ -0,0 +1,36 @@ +package screens; + +// Framework / Drivers layer + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class CreateCourseScreen extends JPanel implements ActionListener { + /* the course name chosen by InstructorUser */ + JTextField courseName = new JTextField(15); + + /* the course instructor */ + JTextField courseInstructor = new JTextField(15); + + /* the part i don't understand ... tasks .... */ + + /* the controller */ + CourseCreationController courseCreationController; + + /** + * A window with a title and JButton + */ + public CreateCourseScreen(CourseCreationController controller) { + this.courseCreationController = controller; + } + + /** + * React to a button click ... + */ + public void actionPerformed(ActionEvent evt) { + System.out.println("Click " + evt.getActionCommand()); + } + + +} diff --git a/src/main/java/screens/FileCourse.java b/src/main/java/screens/FileCourse.java new file mode 100644 index 0000000..4f74e1e --- /dev/null +++ b/src/main/java/screens/FileCourse.java @@ -0,0 +1,83 @@ +package screens; + +import course_creation_use_case.courseCreationDsGateway; +import course_creation_use_case.courseCreationDsRequestModel; + +import java.io.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class FileCourse implements courseCreationDsGateway { + private final File csvFile; + private final Map headers = new HashMap<>(); + private final Map courses = new HashMap<>(); + + public FileCourse(String csvPath) throws IOException { + csvFile = new File(csvPath); + + headers.put("courseName", 0); + headers.put("course instructor", 1); + headers.put("tasks?", 2); + + if (csvFile.length() == 0) { + saveCourse(); + } else { + + BufferedReader reader = new BufferedReader(new FileReader(csvFile)); + reader.readLine(); // skip the header + + String row; + while ((row = reader.readLine()) != null) { + String[] col = row.split(","); + String courseName = String.valueOf(col[headers.get("courseName")]); + String courseInstructor = String.valueOf(col[headers.get("courseInstructor")]); + ArrayList tasks = new ArrayList(); // idk what im doing +// /* String.valueOf(col[headers.get("tasks?")]); */ + courseCreationDsRequestModel course = new courseCreationDsRequestModel(courseName, courseInstructor, tasks); + courses.put(courseName, course); + } + + reader.close(); + + } + + } + + /** + * Add requestModel to storage + * @param requestModel the user information to save + */ + @Override + public void saveCourse(courseCreationDsRequestModel requestModel) { + courses.put(requestModel.getCourseName() ,requestModel); + this.saveCourse(); + } + + private void saveCourse() { + BufferedWriter writer; + try { + writer = new BufferedWriter(new FileWriter(csvFile)); + writer.write(String.join(",", headers.keySet())); + writer.newLine(); + + for (courseCreationDsRequestModel course : courses.values()) { + String line = "%s,%s,%s".format( + course.getCourseName(), course.getCourseInstructor(), course.getTasks()); + writer.write(line); + writer.newLine(); + } + + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + @Override + public boolean existsByCourseID(String identifier) { + return courses.containsKey(identifier); + } + +} diff --git a/src/main/java/screens/InMemoryCourse.java b/src/main/java/screens/InMemoryCourse.java new file mode 100644 index 0000000..6a4fd67 --- /dev/null +++ b/src/main/java/screens/InMemoryCourse.java @@ -0,0 +1,28 @@ +package screens; + +import course_creation_use_case.courseCreationDsGateway; +import course_creation_use_case.courseCreationDsRequestModel; + +import java.util.HashMap; +import java.util.Map; + +public class InMemoryCourse implements courseCreationDsGateway { + final private Map courses = new HashMap<>(); + + /** + * @param identifier the course's course id + * @return whether the course exists + */ + @Override + public boolean existsByCourseID(String identifier) { + return courses.containsKey(identifier); + } + + /** + * @param requestModel the data to save + */ + @Override + public void saveCourse(courseCreationDsRequestModel requestModel) { + System.out.println("Save " + requestModel.getCourseID()); + } +} diff --git a/src/main/java/screens/LabelTextPanel.java b/src/main/java/screens/LabelTextPanel.java new file mode 100644 index 0000000..ce0d357 --- /dev/null +++ b/src/main/java/screens/LabelTextPanel.java @@ -0,0 +1,10 @@ +package screens; + +import javax.swing.*; + +public class LabelTextPanel extends JPanel { + public LabelTextPanel(JPanel label, JTextField textField) { + this.add(label); + this.add(textField); + } +} From 89d11ee730238e916a255de19dbd7f69f1e02cdd Mon Sep 17 00:00:00 2001 From: jltng Date: Fri, 18 Nov 2022 02:04:38 -0500 Subject: [PATCH 07/22] course creation screen loads, not yet responsive --- src/main/java/screens/CreateCourseScreen.java | 48 ++++++++++++++++--- src/main/java/screens/LabelTextPanel.java | 2 +- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/main/java/screens/CreateCourseScreen.java b/src/main/java/screens/CreateCourseScreen.java index 37e2d4d..e52034d 100644 --- a/src/main/java/screens/CreateCourseScreen.java +++ b/src/main/java/screens/CreateCourseScreen.java @@ -3,26 +3,54 @@ // Framework / Drivers layer import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class CreateCourseScreen extends JPanel implements ActionListener { - /* the course name chosen by InstructorUser */ + /** the course name chosen by InstructorUser */ JTextField courseName = new JTextField(15); - /* the course instructor */ + /** the course instructor */ JTextField courseInstructor = new JTextField(15); - /* the part i don't understand ... tasks .... */ + /** the part i don't understand ... tasks .... */ +// JList tasks = new JList(15); - /* the controller */ + + /** the controller */ CourseCreationController courseCreationController; /** - * A window with a title and JButton - */ + * A window with a title and JButton */ public CreateCourseScreen(CourseCreationController controller) { this.courseCreationController = controller; + + JLabel title = new JLabel("Course Creation Screen"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + + LabelTextPanel courseNameInfo = new LabelTextPanel( + new JLabel("Enter course name"), courseName); + LabelTextPanel courseInstructorInfo = new LabelTextPanel( + new JLabel("Enter instructor name"), courseInstructor); + + JButton cancel = new JButton("Cancel"); + JButton save = new JButton("Save"); + + JPanel buttons = new JPanel(); + buttons.add(cancel); + buttons.add(save); + + cancel.addActionListener(this); + save.addActionListener(this); + + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + this.add(title); + this.add(courseNameInfo); + this.add(courseInstructorInfo); + this.add(buttons); + } /** @@ -30,6 +58,14 @@ public CreateCourseScreen(CourseCreationController controller) { */ public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); + +// try { +// courseCreationController.create(courseName.getText(), +// courseInstructor.getText(), tasks.getText()); +// JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); +// } catch (Exception e) { +// JOptionPane.showMessageDialog(this, e.getMessage()); +// } } diff --git a/src/main/java/screens/LabelTextPanel.java b/src/main/java/screens/LabelTextPanel.java index ce0d357..ec714a4 100644 --- a/src/main/java/screens/LabelTextPanel.java +++ b/src/main/java/screens/LabelTextPanel.java @@ -3,7 +3,7 @@ import javax.swing.*; public class LabelTextPanel extends JPanel { - public LabelTextPanel(JPanel label, JTextField textField) { + public LabelTextPanel(JLabel label, JTextField textField) { this.add(label); this.add(textField); } From c7ebd96688ee2047acdd01ccf3f3a25334c1a50e Mon Sep 17 00:00:00 2001 From: jltng Date: Fri, 18 Nov 2022 02:47:18 -0500 Subject: [PATCH 08/22] changed course creation use case files to not include ds request model, commented out ds request model file --- .../courseCreationDsGateway.java | 10 +- .../courseCreationDsRequestModel.java | 80 ++++++++-------- .../courseCreationInputBoundary.java | 13 ++- .../courseCreationPresenter.java | 5 + .../courseCreationRequestModel.java | 19 ++-- .../courseCreationResponseModel.java | 73 +++++++------- .../courseEnrolmentDsGateway.java | 3 +- .../courseEnrolmentDsRequestModel.java | 46 ++++----- src/main/java/entities/StudentUser.java | 2 +- src/main/java/entities/User.java | 2 +- src/main/java/entities/UserWhisperer.java | 2 +- src/main/java/entities/internalUserList.java | 2 +- src/main/java/screens/FileCourse.java | 96 +++++++++++++++++-- src/main/java/screens/InMemoryCourse.java | 29 +++++- 14 files changed, 254 insertions(+), 128 deletions(-) diff --git a/src/main/java/course_creation_use_case/courseCreationDsGateway.java b/src/main/java/course_creation_use_case/courseCreationDsGateway.java index bb2ebab..d385d86 100644 --- a/src/main/java/course_creation_use_case/courseCreationDsGateway.java +++ b/src/main/java/course_creation_use_case/courseCreationDsGateway.java @@ -2,13 +2,17 @@ // Use case layer -// Notes: -// ** the methods the repo needs to implement for the interactor to do its job +/* +Notes: +DONE? +- the methods the repo needs to implement for the interactor to do its job + */ public interface courseCreationDsGateway { // boolean existsByCourseName(String courseIdentifier); // boolean existsByInstructorName(String instructorIdentifier); boolean existsByCourseID(String courseIdentifier); - void saveCourse(courseCreationDsRequestModel requestModel); +// void saveCourse(courseCreationDsRequestModel requestModel); + void saveCourse(courseCreationRequestModel requestModel); } diff --git a/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java b/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java index 2844c4f..4f8cb5f 100644 --- a/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java +++ b/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java @@ -1,40 +1,40 @@ -package course_creation_use_case; - -// Use case layer - -// Notes: -// DONE? - - -import java.util.ArrayList; - -public class courseCreationDsRequestModel { - private final String courseName; - private final String courseInstructor; - private final String courseID; - private ArrayList tasks; - - public courseCreationDsRequestModel(String courseName, String courseInstructor, ArrayList tasks) { - this.courseName = courseName; - this.courseInstructor = courseInstructor; - this.courseID = courseName + courseInstructor; - this.tasks = tasks; - } - - public String getCourseName() { - return courseName; - } - public String getCourseInstructor() { - return courseInstructor; - } - public String getCourseID() { - return courseID; - } - public ArrayList getTasks() { - return tasks; - } - - public void setTasks(ArrayList tasks) { - this.tasks = tasks; - } -} +//package course_creation_use_case; +// +//// Use case layer +// +//// Notes: +//// DONE? ACTUALLY NOT EVEN NEEDED????? +// +// +//import java.util.ArrayList; +// +//public class courseCreationDsRequestModel { +// private final String courseName; +// private final String courseInstructor; +// private final String courseID; +// private ArrayList tasks; +// +// public courseCreationDsRequestModel(String courseName, String courseInstructor, ArrayList tasks) { +// this.courseName = courseName; +// this.courseInstructor = courseInstructor; +// this.courseID = courseName + courseInstructor; +// this.tasks = tasks; +// } +// +// public String getCourseName() { +// return courseName; +// } +// public String getCourseInstructor() { +// return courseInstructor; +// } +// public String getCourseID() { +// return courseID; +// } +// public ArrayList getTasks() { +// return tasks; +// } +// +// public void setTasks(ArrayList tasks) { +// this.tasks = tasks; +// } +//} diff --git a/src/main/java/course_creation_use_case/courseCreationInputBoundary.java b/src/main/java/course_creation_use_case/courseCreationInputBoundary.java index 2931d4c..0c628d0 100644 --- a/src/main/java/course_creation_use_case/courseCreationInputBoundary.java +++ b/src/main/java/course_creation_use_case/courseCreationInputBoundary.java @@ -2,11 +2,14 @@ // Use case layer -// Notes: -// DONE -// ** the public interface for calling the use case -// boundaries are interfaces -// input boundary is between the controller and use case + +/* +Notes: + DONE +- the public interface for calling the use case +- boundaries are interfaces +- input boundary is between the controller and use case + */ public interface courseCreationInputBoundary { courseCreationResponseModel create(courseCreationRequestModel requestModel); diff --git a/src/main/java/course_creation_use_case/courseCreationPresenter.java b/src/main/java/course_creation_use_case/courseCreationPresenter.java index 5e947ee..a76639b 100644 --- a/src/main/java/course_creation_use_case/courseCreationPresenter.java +++ b/src/main/java/course_creation_use_case/courseCreationPresenter.java @@ -2,6 +2,11 @@ // Use case layer +/* +Notes: +Done? i guess + */ + public interface courseCreationPresenter { /* when course is successfully created diff --git a/src/main/java/course_creation_use_case/courseCreationRequestModel.java b/src/main/java/course_creation_use_case/courseCreationRequestModel.java index c7083c0..8a45e33 100644 --- a/src/main/java/course_creation_use_case/courseCreationRequestModel.java +++ b/src/main/java/course_creation_use_case/courseCreationRequestModel.java @@ -2,10 +2,13 @@ // Use case layer -// Notes: -// DONE? -// requests what is needed for its input data (what person in front of computer enters) -// do NOT depend on anything NOR have any references to Entity objects: violates SRP +/* + Notes: + DONE? +- requests what is needed for its input data (what person in front of computer enters) +- do NOT depend on anything NOR have any references to Entity objects: violates SRP + */ + import java.util.ArrayList; @@ -22,7 +25,9 @@ public courseCreationRequestModel(String courseName, String courseInstructor, Ar this.tasks = tasks; } - String getCourseName() { + /** + * all getters changed to public, used by FileCourse */ + public String getCourseName() { return courseName; } @@ -31,7 +36,7 @@ public void setCourseName() { this.courseName = courseName; } - String getCourseInstructor() { + public String getCourseInstructor() { return courseInstructor; } @@ -40,7 +45,7 @@ public void setCourseInstructor() { this.courseInstructor = courseInstructor; } - String getCourseID() { + public String getCourseID() { return courseID; } diff --git a/src/main/java/course_creation_use_case/courseCreationResponseModel.java b/src/main/java/course_creation_use_case/courseCreationResponseModel.java index ba796c5..0465059 100644 --- a/src/main/java/course_creation_use_case/courseCreationResponseModel.java +++ b/src/main/java/course_creation_use_case/courseCreationResponseModel.java @@ -4,9 +4,11 @@ // Use case layer -// Notes: -// the output data produced; returns the response as the output -// do NOT depend on anything NOR have any references to Entity objects: violates SRP +/* +Notes: +- the output data produced; returns the response as the output +- do NOT depend on anything NOR have any references to Entity objects: violates SRP + */ public class courseCreationResponseModel { // String courseName; @@ -28,38 +30,39 @@ public ArrayList getTasks() { return tasks; } - // do not think this is needed -// public void setTasks() { -// this.tasks = tasks; -// } + /* do not think this is needed: + public void setTasks() { + this.tasks = tasks; + } -// public courseCreationResponseModel(String courseName, String instructorName) { -// this.courseName = courseName; -// this.instructorName = instructorName; -// } -// -// public String getCourseName() { -// return this.courseName; -// } -// -// public void setCourseName() { -// this.courseName = courseName; -// } -// -// public String getInstructorName() { -// return this.instructorName; -// } -// -// public void setInstructorName() { -// this.instructorName = instructorName; -// } -// -// public ArrayList getTasks() { -// return this.tasks; -// } -// -// public void setTasks() { -// this.tasks = tasks; -// } + public courseCreationResponseModel(String courseName, String instructorName) { + this.courseName = courseName; + this.instructorName = instructorName; + } + + public String getCourseName() { + return this.courseName; + } + + public void setCourseName() { + this.courseName = courseName; + } + + public String getInstructorName() { + return this.instructorName; + } + + public void setInstructorName() { + this.instructorName = instructorName; + } + + public ArrayList getTasks() { + return this.tasks; + } + + public void setTasks() { + this.tasks = tasks; + } + */ } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java b/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java index eb0454e..0b95755 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java @@ -6,5 +6,6 @@ public interface courseEnrolmentDsGateway { /* checks if student is in the course */ boolean existsByStudent(String studentIdentifier); - void saveStudent(courseEnrolmentDsRequestModel requestModel); +// void saveStudent(courseEnrolmentDsRequestModel requestModel); + void saveStudent(courseEnrolmentRequestModel requestModel); } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java b/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java index 28d954d..a329f4f 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java @@ -1,23 +1,23 @@ -package course_enrolment_use_case; - -public class courseEnrolmentDsRequestModel { - private final String courseName; - private final String courseInstructor; - private final String courseID; // searches using this - - public courseEnrolmentDsRequestModel(String courseName, String courseInstructor) { - this.courseName = courseName; - this.courseInstructor = courseInstructor; - this.courseID = courseName + courseInstructor; - } - - public String getCourseName() { - return courseName; - } - public String getCourseInstructor() { - return courseInstructor; - } - public String getCourseID() { - return courseID; - } -} +//package course_enrolment_use_case; +// +//public class courseEnrolmentDssRequestModel { +// private final String courseName; +// private final String courseInstructor; +// private final String courseID; // searches using this +// +// public courseEnrolmentDsRequestModel(String courseName, String courseInstructor) { +// this.courseName = courseName; +// this.courseInstructor = courseInstructor; +// this.courseID = courseName + courseInstructor; +// } +// +// public String getCourseName() { +// return courseName; +// } +// public String getCourseInstructor() { +// return courseInstructor; +// } +// public String getCourseID() { +// return courseID; +// } +//} diff --git a/src/main/java/entities/StudentUser.java b/src/main/java/entities/StudentUser.java index 0966ff6..aaabbcb 100644 --- a/src/main/java/entities/StudentUser.java +++ b/src/main/java/entities/StudentUser.java @@ -1,4 +1,4 @@ -package entities; +package Entities; import java.time.LocalDateTime; import java.util.ArrayList; diff --git a/src/main/java/entities/User.java b/src/main/java/entities/User.java index 85a510f..f6a0b05 100644 --- a/src/main/java/entities/User.java +++ b/src/main/java/entities/User.java @@ -1,4 +1,4 @@ -package entities; +package Entities; // Entity public abstract class User { diff --git a/src/main/java/entities/UserWhisperer.java b/src/main/java/entities/UserWhisperer.java index ef96570..0f29fe5 100644 --- a/src/main/java/entities/UserWhisperer.java +++ b/src/main/java/entities/UserWhisperer.java @@ -1,4 +1,4 @@ -package entities; +package Entities; // Entity diff --git a/src/main/java/entities/internalUserList.java b/src/main/java/entities/internalUserList.java index 962010d..ccd5879 100644 --- a/src/main/java/entities/internalUserList.java +++ b/src/main/java/entities/internalUserList.java @@ -1,4 +1,4 @@ -package entities; +package Entities; import java.util.ArrayList; diff --git a/src/main/java/screens/FileCourse.java b/src/main/java/screens/FileCourse.java index 4f74e1e..1c743ef 100644 --- a/src/main/java/screens/FileCourse.java +++ b/src/main/java/screens/FileCourse.java @@ -1,8 +1,13 @@ package screens; import course_creation_use_case.courseCreationDsGateway; -import course_creation_use_case.courseCreationDsRequestModel; +//import course_creation_use_case.courseCreationDsRequestModel; +import course_creation_use_case.courseCreationRequestModel; +/* + * Notes: + * I think for csv file? so columns is what each course entity is? im assuming? idek man + */ import java.io.*; import java.util.ArrayList; import java.util.HashMap; @@ -11,13 +16,13 @@ public class FileCourse implements courseCreationDsGateway { private final File csvFile; private final Map headers = new HashMap<>(); - private final Map courses = new HashMap<>(); + private final Map courses = new HashMap<>(); public FileCourse(String csvPath) throws IOException { csvFile = new File(csvPath); - headers.put("courseName", 0); - headers.put("course instructor", 1); + headers.put("course_name", 0); + headers.put("course_instructor", 1); headers.put("tasks?", 2); if (csvFile.length() == 0) { @@ -34,7 +39,7 @@ public FileCourse(String csvPath) throws IOException { String courseInstructor = String.valueOf(col[headers.get("courseInstructor")]); ArrayList tasks = new ArrayList(); // idk what im doing // /* String.valueOf(col[headers.get("tasks?")]); */ - courseCreationDsRequestModel course = new courseCreationDsRequestModel(courseName, courseInstructor, tasks); + courseCreationRequestModel course = new courseCreationRequestModel(courseName, courseInstructor, tasks); courses.put(courseName, course); } @@ -49,7 +54,7 @@ public FileCourse(String csvPath) throws IOException { * @param requestModel the user information to save */ @Override - public void saveCourse(courseCreationDsRequestModel requestModel) { + public void saveCourse(courseCreationRequestModel requestModel) { courses.put(requestModel.getCourseName() ,requestModel); this.saveCourse(); } @@ -61,7 +66,7 @@ private void saveCourse() { writer.write(String.join(",", headers.keySet())); writer.newLine(); - for (courseCreationDsRequestModel course : courses.values()) { + for (courseCreationRequestModel course : courses.values()) { String line = "%s,%s,%s".format( course.getCourseName(), course.getCourseInstructor(), course.getTasks()); writer.write(line); @@ -81,3 +86,80 @@ public boolean existsByCourseID(String identifier) { } } + +/* + * with ds request but apparently not needed so + */ +//public class FileCourse implements courseCreationDsGateway { +// private final File csvFile; +// private final Map headers = new HashMap<>(); +// private final Map courses = new HashMap<>(); +// +// public FileCourse(String csvPath) throws IOException { +// csvFile = new File(csvPath); +// +// headers.put("courseName", 0); +// headers.put("course instructor", 1); +// headers.put("tasks?", 2); +// +// if (csvFile.length() == 0) { +// saveCourse(); +// } else { +// +// BufferedReader reader = new BufferedReader(new FileReader(csvFile)); +// reader.readLine(); // skip the header +// +// String row; +// while ((row = reader.readLine()) != null) { +// String[] col = row.split(","); +// String courseName = String.valueOf(col[headers.get("courseName")]); +// String courseInstructor = String.valueOf(col[headers.get("courseInstructor")]); +// ArrayList tasks = new ArrayList(); // idk what im doing +//// /* String.valueOf(col[headers.get("tasks?")]); */ +// courseCreationDsRequestModel course = new courseCreationDsRequestModel(courseName, courseInstructor, tasks); +// courses.put(courseName, course); +// } +// +// reader.close(); +// +// } +// +// } +// +// /** +// * Add requestModel to storage +// * @param requestModel the user information to save +// */ +// @Override +// public void saveCourse(courseCreationDsRequestModel requestModel) { +// courses.put(requestModel.getCourseName() ,requestModel); +// this.saveCourse(); +// } +// +// private void saveCourse() { +// BufferedWriter writer; +// try { +// writer = new BufferedWriter(new FileWriter(csvFile)); +// writer.write(String.join(",", headers.keySet())); +// writer.newLine(); +// +// for (courseCreationDsRequestModel course : courses.values()) { +// String line = "%s,%s,%s".format( +// course.getCourseName(), course.getCourseInstructor(), course.getTasks()); +// writer.write(line); +// writer.newLine(); +// } +// +// writer.close(); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// +// } +// +// @Override +// public boolean existsByCourseID(String identifier) { +// return courses.containsKey(identifier); +// } +// +//} diff --git a/src/main/java/screens/InMemoryCourse.java b/src/main/java/screens/InMemoryCourse.java index 6a4fd67..6cd8b6e 100644 --- a/src/main/java/screens/InMemoryCourse.java +++ b/src/main/java/screens/InMemoryCourse.java @@ -1,13 +1,15 @@ package screens; import course_creation_use_case.courseCreationDsGateway; -import course_creation_use_case.courseCreationDsRequestModel; +//import course_creation_use_case.courseCreationDsRequestModel; +import course_creation_use_case.courseCreationRequestModel; + import java.util.HashMap; import java.util.Map; public class InMemoryCourse implements courseCreationDsGateway { - final private Map courses = new HashMap<>(); + final private Map courses = new HashMap<>(); /** * @param identifier the course's course id @@ -22,7 +24,28 @@ public boolean existsByCourseID(String identifier) { * @param requestModel the data to save */ @Override - public void saveCourse(courseCreationDsRequestModel requestModel) { + public void saveCourse(courseCreationRequestModel requestModel) { System.out.println("Save " + requestModel.getCourseID()); } } + +//public class InMemoryCourse implements courseCreationDsGateway { +// final private Map courses = new HashMap<>(); +// +// /** +// * @param identifier the course's course id +// * @return whether the course exists +// */ +// @Override +// public boolean existsByCourseID(String identifier) { +// return courses.containsKey(identifier); +// } +// +// /** +// * @param requestModel the data to save +// */ +// @Override +// public void saveCourse(courseCreationDsRequestModel requestModel) { +// System.out.println("Save " + requestModel.getCourseID()); +// } +//} From f95d5224a6f17b1af5b9b8cfc273a4a23687d7d3 Mon Sep 17 00:00:00 2001 From: jltng Date: Fri, 18 Nov 2022 09:49:05 -0500 Subject: [PATCH 09/22] started screens for course enrolment use case --- .../courseCreationInteractor.java | 8 ++- .../courseEnrolmentInputBoundary.java | 3 + .../courseEnrolmentInteractor.java | 2 +- .../courseEnrolmentPresenter.java | 4 ++ .../courseEnrolmentRequestModel.java | 3 + .../screens/CourseEnrolmentController.java | 20 ++++++ .../java/screens/CourseEnrolmentFailed.java | 8 +++ .../CourseEnrolmentResponseFormatter.java | 20 ++++++ .../java/screens/CourseEnrolmentScreen.java | 64 +++++++++++++++++++ src/main/java/screens/CreateCourseScreen.java | 10 ++- 10 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 src/main/java/screens/CourseEnrolmentController.java create mode 100644 src/main/java/screens/CourseEnrolmentFailed.java create mode 100644 src/main/java/screens/CourseEnrolmentResponseFormatter.java create mode 100644 src/main/java/screens/CourseEnrolmentScreen.java diff --git a/src/main/java/course_creation_use_case/courseCreationInteractor.java b/src/main/java/course_creation_use_case/courseCreationInteractor.java index 361cc82..ad2c055 100644 --- a/src/main/java/course_creation_use_case/courseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/courseCreationInteractor.java @@ -4,6 +4,12 @@ /* Notes VERY CONFUSED --> NEED COURSE FACTORY? +- ok i think the problem is i need to decide how to store date: + 1. csv file with rows (i want, but how to store courseID as well?) + 2. coursefactory ???? whatever that is + 3. courseMAp ...... not really useful for me? + - and problemo is: which one of them is persistent / serializable? + ** the class that runs the use case (subclass of input boundary) the highest level concept; the most protected */ @@ -41,7 +47,7 @@ If the course id (same course name and instructor name) already exists, new return null; /* - * what is a courseFactory and is it needed + * what is a courseFactory */ // Course course = courseFactory.create(requestModel.getCourseID(), requestModel.getTasks()); diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java b/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java index 850dde7..0a148e3 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java @@ -2,6 +2,9 @@ // Use case layer +/* +* DONE +* */ public interface courseEnrolmentInputBoundary { courseEnrolmentResponseModel create(courseEnrolmentRequestModel requestModel); } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java b/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java index 8056d2b..453838a 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java @@ -30,7 +30,7 @@ public courseEnrolmentResponseModel create(courseEnrolmentRequestModel requestMo map is courseid --> Course objects with valid courseid, go to Course.students and check if it contains STUDENT's id */ -// if (CourseMap.mapping(requestModel.getCourseID()).contains(courseEnrolmentDsGateway.existsByStudent(requestModel.getStudentID()))) { +// if (CourseMap.value(requestModel.getCourseID()).contains(courseEnrolmentDsGateway.existsByStudent(requestModel.getStudentID()))) { // return courseEnrolmentPresenter.prepareFailView("Already enrolled in course."); // } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java b/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java index e314707..ee100f1 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java @@ -2,6 +2,10 @@ // Use case layer +/* +* Done? +* */ + public interface courseEnrolmentPresenter { /* when course is found */ courseEnrolmentResponseModel prepareSuccessView(courseEnrolmentResponseModel newStudent); diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java b/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java index 9cd28c0..a17ab7b 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java +++ b/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java @@ -13,6 +13,9 @@ public courseEnrolmentRequestModel(String courseName, String courseInstructor) { this.courseID = courseName + courseInstructor; } + /** + * Change getters to public? + */ String getCourseName() { return courseName; } diff --git a/src/main/java/screens/CourseEnrolmentController.java b/src/main/java/screens/CourseEnrolmentController.java new file mode 100644 index 0000000..6e2011e --- /dev/null +++ b/src/main/java/screens/CourseEnrolmentController.java @@ -0,0 +1,20 @@ +package screens; + +import course_enrolment_use_case.courseEnrolmentInputBoundary; +import course_enrolment_use_case.courseEnrolmentRequestModel; +import course_enrolment_use_case.courseEnrolmentResponseModel; + +public class CourseEnrolmentController { + final courseEnrolmentInputBoundary enrolmentInput; + public CourseEnrolmentController(courseEnrolmentInputBoundary enrolmentGateway) { + this.enrolmentInput = enrolmentGateway; + } + + courseEnrolmentResponseModel create(String courseID, String instructorID) { + courseEnrolmentRequestModel requestModel = new courseEnrolmentRequestModel( + courseID, instructorID); + + return enrolmentInput.create(requestModel); + } + +} diff --git a/src/main/java/screens/CourseEnrolmentFailed.java b/src/main/java/screens/CourseEnrolmentFailed.java new file mode 100644 index 0000000..9ee96b3 --- /dev/null +++ b/src/main/java/screens/CourseEnrolmentFailed.java @@ -0,0 +1,8 @@ +package screens; + + +public class CourseEnrolmentFailed extends RuntimeException { + public CourseEnrolmentFailed(String error) { + super(error); + } +} diff --git a/src/main/java/screens/CourseEnrolmentResponseFormatter.java b/src/main/java/screens/CourseEnrolmentResponseFormatter.java new file mode 100644 index 0000000..6431cbb --- /dev/null +++ b/src/main/java/screens/CourseEnrolmentResponseFormatter.java @@ -0,0 +1,20 @@ +package screens; + +// Interfaces adapters layer + +import course_enrolment_use_case.courseEnrolmentPresenter; +import course_enrolment_use_case.courseEnrolmentResponseModel; + +public class CourseEnrolmentResponseFormatter implements courseEnrolmentPresenter { + + @Override + public courseEnrolmentResponseModel prepareSuccessView(courseEnrolmentResponseModel response) { + /* what is this */ + return response; + } + + @Override + public courseEnrolmentResponseModel prepareFailView(String error) { + throw new CourseEnrolmentFailed(error); + } +} diff --git a/src/main/java/screens/CourseEnrolmentScreen.java b/src/main/java/screens/CourseEnrolmentScreen.java new file mode 100644 index 0000000..3727167 --- /dev/null +++ b/src/main/java/screens/CourseEnrolmentScreen.java @@ -0,0 +1,64 @@ +package screens; + +// Framework / Drivers layer + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class CourseEnrolmentScreen extends JPanel implements ActionListener { + /** student enters course name */ + JTextField courseName = new JTextField(15); + + /** student enters course instructor */ + JTextField courseInstructor = new JTextField(15); + + /** the controller */ + CourseEnrolmentController courseEnrolmentController; + + /** + * Window with title and JButtons + */ + public CourseEnrolmentScreen(CourseEnrolmentController controller) { + this.courseEnrolmentController = controller; + + JLabel title = new JLabel("Course Enrolment Screen"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + + LabelTextPanel courseNameInfo = new LabelTextPanel( + new JLabel("Enter course name"), courseName); + LabelTextPanel courseInstructorInfo = new LabelTextPanel( + new JLabel("Enter instructor name"), courseInstructor); + + JButton cancel = new JButton("Cancel"); + JButton search = new JButton("Search"); + + JPanel buttons = new JPanel(); + buttons.add(cancel); + buttons.add(search); + + cancel.addActionListener(this); + search.addActionListener(this); + + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + this.add(title); + this.add(courseNameInfo); + this.add(courseInstructorInfo); + this.add(buttons); + } + + /** + * reacting to button clicks? + */ + public void actionPerformed(ActionEvent evt) { + System.out.println("Click " + evt.getActionCommand()); + + try { +// courseEnrolmentController.cre + } catch (Exception e) { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + } +} diff --git a/src/main/java/screens/CreateCourseScreen.java b/src/main/java/screens/CreateCourseScreen.java index e52034d..3df5e26 100644 --- a/src/main/java/screens/CreateCourseScreen.java +++ b/src/main/java/screens/CreateCourseScreen.java @@ -59,14 +59,12 @@ public CreateCourseScreen(CourseCreationController controller) { public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); -// try { + try { // courseCreationController.create(courseName.getText(), // courseInstructor.getText(), tasks.getText()); // JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); -// } catch (Exception e) { -// JOptionPane.showMessageDialog(this, e.getMessage()); -// } + } catch (Exception e) { + JOptionPane.showMessageDialog(this, e.getMessage()); + } } - - } From c71b7744657c4dfe06937292137af0b94335f7f8 Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 04:17:03 -0500 Subject: [PATCH 10/22] renamed entity layer files to java naming convention, added course found screen --- src/main/java/Entities/CourseFactory.java | 25 ++++---- src/main/java/Entities/CourseMap.java | 2 +- src/main/java/Main.java | 64 ++++++++++++++----- ...eway.java => CourseCreationDsGateway.java} | 4 +- ....java => CourseCreationInputBoundary.java} | 4 +- ...tor.java => CourseCreationInteractor.java} | 48 ++++++++++---- ...nter.java => CourseCreationPresenter.java} | 6 +- ...l.java => CourseCreationRequestModel.java} | 4 +- ....java => CourseCreationResponseModel.java} | 4 +- ...way.java => CourseEnrolmentDsGateway.java} | 4 +- .../CourseEnrolmentInputBoundary.java | 10 +++ ...or.java => CourseEnrolmentInteractor.java} | 12 ++-- ...ter.java => CourseEnrolmentPresenter.java} | 6 +- ....java => CourseEnrolmentRequestModel.java} | 4 +- ...java => CourseEnrolmentResponseModel.java} | 4 +- .../courseEnrolmentInputBoundary.java | 10 --- .../screens/CourseCreationController.java | 14 ++-- .../CourseCreationResponseFormatter.java | 10 +-- .../screens/CourseEnrolmentController.java | 14 ++-- .../CourseEnrolmentResponseFormatter.java | 10 +-- src/main/java/screens/CourseFoundScreen.java | 42 ++++++++++++ src/main/java/screens/CreateCourseScreen.java | 22 +++++-- src/main/java/screens/FileCourse.java | 14 ++-- src/main/java/screens/InMemoryCourse.java | 10 +-- 24 files changed, 230 insertions(+), 117 deletions(-) rename src/main/java/course_creation_use_case/{courseCreationDsGateway.java => CourseCreationDsGateway.java} (79%) rename src/main/java/course_creation_use_case/{courseCreationInputBoundary.java => CourseCreationInputBoundary.java} (67%) rename src/main/java/course_creation_use_case/{courseCreationInteractor.java => CourseCreationInteractor.java} (53%) rename src/main/java/course_creation_use_case/{courseCreationPresenter.java => CourseCreationPresenter.java} (59%) rename src/main/java/course_creation_use_case/{courseCreationRequestModel.java => CourseCreationRequestModel.java} (92%) rename src/main/java/course_creation_use_case/{courseCreationResponseModel.java => CourseCreationResponseModel.java} (92%) rename src/main/java/course_enrolment_use_case/{courseEnrolmentDsGateway.java => CourseEnrolmentDsGateway.java} (67%) create mode 100644 src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java rename src/main/java/course_enrolment_use_case/{courseEnrolmentInteractor.java => CourseEnrolmentInteractor.java} (76%) rename src/main/java/course_enrolment_use_case/{courseEnrolmentPresenter.java => CourseEnrolmentPresenter.java} (54%) rename src/main/java/course_enrolment_use_case/{courseEnrolmentRequestModel.java => CourseEnrolmentRequestModel.java} (87%) rename src/main/java/course_enrolment_use_case/{courseEnrolmentResponseModel.java => CourseEnrolmentResponseModel.java} (85%) delete mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java create mode 100644 src/main/java/screens/CourseFoundScreen.java diff --git a/src/main/java/Entities/CourseFactory.java b/src/main/java/Entities/CourseFactory.java index 7852ca0..b6d5d39 100644 --- a/src/main/java/Entities/CourseFactory.java +++ b/src/main/java/Entities/CourseFactory.java @@ -1,11 +1,14 @@ -package Entities; - -// Entity layer - -import java.util.ArrayList; - -public class CourseFactory { - public Course create(String courseName, String courseInstructor, ArrayList tasks) { - return new Course(courseName, courseInstructor, tasks); - } -} +//package Entities; +// +//// Entity layer +// +//import java.util.ArrayList; +// +//public class CourseFactory { +// public Course create(String courseName, String courseInstructor, ArrayList tasks) { +// return new Course(courseName, courseInstructor, tasks); +// } +//} +/** + * no longer needed! just for if you need to work with different types of users + */ \ No newline at end of file diff --git a/src/main/java/Entities/CourseMap.java b/src/main/java/Entities/CourseMap.java index 41453b3..3db8dce 100644 --- a/src/main/java/Entities/CourseMap.java +++ b/src/main/java/Entities/CourseMap.java @@ -24,7 +24,7 @@ public Course findCourse(String id) { * @param course the course associated with Course * @return if the course has been added */ - public boolean addCourse(String id, Course course) { + public static boolean addCourse(String id, Course course) { if (courseMap.containsKey(id)) { return false; } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 76047e4..df563ec 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,18 +1,49 @@ -import Entities.CourseFactory; -import course_creation_use_case.courseCreationDsGateway; -import course_creation_use_case.courseCreationInputBoundary; -import course_creation_use_case.courseCreationInteractor; -import course_creation_use_case.courseCreationPresenter; -import screens.CourseCreationController; -import screens.CourseCreationResponseFormatter; -import screens.CreateCourseScreen; -import screens.FileCourse; +//import Entities.CourseFactory; +import Entities.CourseMap; +import course_creation_use_case.CourseCreationDsGateway; +import course_creation_use_case.CourseCreationInputBoundary; +import course_creation_use_case.CourseCreationInteractor; +import course_creation_use_case.CourseCreationPresenter; +import screens.*; import javax.swing.*; import java.awt.*; import java.io.IOException; public class Main { + +// public static void main(String[] args) { +// +// /** build main program window */ +// JFrame application = new JFrame("Course Enrolment Example"); +// CardLayout cardLayout = new CardLayout(); +// JPanel screens = new JPanel(cardLayout); +// application.add(screens); +// +// /** create parts to plug into the use case + entities engine */ +// courseEnrolmentDsGateway course = new Course(CourseMap.addCourse()); +//// try { +//// course = new FileCourse("./courses.csv"); +//// } catch (IOException e) { +//// throw new RuntimeException("Could not create file."); +//// } +// courseEnrolmentPresenter presenter = new CourseEnrolmentResponseFormatter(); +// courseEnrolmentInputBoundary interactor = new courseEnrolmentInteractor( +// course, presenter); +// CourseEnrolmentController courseEnrolmentController = new CourseEnrolmentController( +// interactor +// ); +// +// // COURSE ENROLMENT build the GUI, plugging in the parts +// CourseEnrolmentScreen courseEnrolmentScreen = new CourseEnrolmentScreen(courseEnrolmentController); +// screens.add(courseEnrolmentScreen, "enter course name"); +// cardLayout.show(screens, "enrol in course"); +// application.pack(); +// application.setVisible(true); +// +// } + +// /** course creation screen public static void main(String[] args) { // build main program window @@ -22,21 +53,24 @@ public static void main(String[] args) { application.add(screens); // create parts to plug into the use case + entities engine - courseCreationDsGateway course; + CourseCreationDsGateway course; try { course = new FileCourse("./courses.csv"); } catch (IOException e) { throw new RuntimeException("Could not create file."); } - courseCreationPresenter presenter = new CourseCreationResponseFormatter(); - CourseFactory courseFactory = new CourseFactory(); - courseCreationInputBoundary interactor = new courseCreationInteractor( - course, presenter, courseFactory); + CourseCreationPresenter presenter = new CourseCreationResponseFormatter(); + CourseMap courseMap = new CourseMap(); + +// CourseFactory courseFactory = new CourseFactory(); + + CourseCreationInputBoundary interactor = new CourseCreationInteractor( + course, presenter, courseMap); CourseCreationController courseCreationController = new CourseCreationController( interactor ); - // build the GUI, plugging in the parts + // COURSE CREATION build the GUI, plugging in the parts CreateCourseScreen createCourseScreen = new CreateCourseScreen(courseCreationController); screens.add(createCourseScreen, "create a new course"); cardLayout.show(screens, "create course"); diff --git a/src/main/java/course_creation_use_case/courseCreationDsGateway.java b/src/main/java/course_creation_use_case/CourseCreationDsGateway.java similarity index 79% rename from src/main/java/course_creation_use_case/courseCreationDsGateway.java rename to src/main/java/course_creation_use_case/CourseCreationDsGateway.java index d385d86..5ac9d5d 100644 --- a/src/main/java/course_creation_use_case/courseCreationDsGateway.java +++ b/src/main/java/course_creation_use_case/CourseCreationDsGateway.java @@ -8,11 +8,11 @@ - the methods the repo needs to implement for the interactor to do its job */ -public interface courseCreationDsGateway { +public interface CourseCreationDsGateway { // boolean existsByCourseName(String courseIdentifier); // boolean existsByInstructorName(String instructorIdentifier); boolean existsByCourseID(String courseIdentifier); // void saveCourse(courseCreationDsRequestModel requestModel); - void saveCourse(courseCreationRequestModel requestModel); + void saveCourse(CourseCreationRequestModel requestModel); } diff --git a/src/main/java/course_creation_use_case/courseCreationInputBoundary.java b/src/main/java/course_creation_use_case/CourseCreationInputBoundary.java similarity index 67% rename from src/main/java/course_creation_use_case/courseCreationInputBoundary.java rename to src/main/java/course_creation_use_case/CourseCreationInputBoundary.java index 0c628d0..afd1441 100644 --- a/src/main/java/course_creation_use_case/courseCreationInputBoundary.java +++ b/src/main/java/course_creation_use_case/CourseCreationInputBoundary.java @@ -11,6 +11,6 @@ - the public interface for calling the use case - input boundary is between the controller and use case */ -public interface courseCreationInputBoundary { - courseCreationResponseModel create(courseCreationRequestModel requestModel); +public interface CourseCreationInputBoundary { + CourseCreationResponseModel create(CourseCreationRequestModel requestModel); } diff --git a/src/main/java/course_creation_use_case/courseCreationInteractor.java b/src/main/java/course_creation_use_case/CourseCreationInteractor.java similarity index 53% rename from src/main/java/course_creation_use_case/courseCreationInteractor.java rename to src/main/java/course_creation_use_case/CourseCreationInteractor.java index ad2c055..85da0de 100644 --- a/src/main/java/course_creation_use_case/courseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/CourseCreationInteractor.java @@ -14,22 +14,31 @@ the highest level concept; the most protected */ -import Entities.CourseFactory; +//import Entities.CourseFactory; +import Entities.CourseMap; -public class courseCreationInteractor implements courseCreationInputBoundary { - final courseCreationDsGateway courseCreationDSGateway; - final courseCreationPresenter courseCreationPresenter; - final CourseFactory courseFactory; +public class CourseCreationInteractor implements CourseCreationInputBoundary { + final CourseCreationDsGateway courseCreationDSGateway; + final CourseCreationPresenter courseCreationPresenter; +// final CourseFactory courseFactory; + final CourseMap courseMap; - public courseCreationInteractor(courseCreationDsGateway courseCreationDSGateway, courseCreationPresenter courseCreationPresenter, - CourseFactory courseFactory) { + public CourseCreationInteractor(CourseCreationDsGateway courseCreationDSGateway, CourseCreationPresenter courseCreationPresenter, + CourseMap courseMap) { this.courseCreationDSGateway = courseCreationDSGateway; this.courseCreationPresenter = courseCreationPresenter; - this.courseFactory = courseFactory; + this.courseMap = courseMap; } +// public courseCreationInteractor(courseCreationDsGateway courseCreationDSGateway, courseCreationPresenter courseCreationPresenter, +// CourseFactory courseFactory) { +// this.courseCreationDSGateway = courseCreationDSGateway; +// this.courseCreationPresenter = courseCreationPresenter; +// this.courseFactory = courseFactory; +// } + @Override - public courseCreationResponseModel create(courseCreationRequestModel requestModel) { + public CourseCreationResponseModel create(CourseCreationRequestModel requestModel) { /* At least one info box left blank */ if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") || requestModel.getTasks().isEmpty()) { return courseCreationPresenter.prepareFailView("Please fill in all required information."); @@ -50,13 +59,26 @@ If the course id (same course name and instructor name) already exists, new * what is a courseFactory */ -// Course course = courseFactory.create(requestModel.getCourseID(), requestModel.getTasks()); -// -// /* checks passed, course successfully created and saved */ + /** confused lol + Course course = CourseMap.addCourse(requestModel.getCourseID(), course); + Course course1 = CourseMap.addCourse(requestModel.getCourseID(), requestModel.getTasks()); + */ + + /** checks passed, course successfully created and saved + courseCreationRequestModel courseCreationModel = new courseCreationRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); + courseCreationDSGateway.saveCourse(courseCreationModel); // courseCreationDSRequestModel courseCreationDSModel = new courseCreationDSRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); // courseCreationDSGateway.saveCourse(courseCreationDSModel); + */ // -// /* checks passed, course sent to presenter */ + /** checks passed, course sent to presenter */ +// courseCreationResponseModel courseResponseModel = new courseCreationResponseModel( +// course.getCourseID(), course.getTasks()); +// return courseCreationPresenter.prepareSuccessView(courseResponseModel); + + + /** + * below is not it */ // courseCreationResponseModel courseResponseModel = new courseCreationResponseModel( // course.getCourseID(), course.getTasks()); // return courseCreationPresenter.prepareFailViewSuccessView(courseResponseModel); diff --git a/src/main/java/course_creation_use_case/courseCreationPresenter.java b/src/main/java/course_creation_use_case/CourseCreationPresenter.java similarity index 59% rename from src/main/java/course_creation_use_case/courseCreationPresenter.java rename to src/main/java/course_creation_use_case/CourseCreationPresenter.java index a76639b..c35aae3 100644 --- a/src/main/java/course_creation_use_case/courseCreationPresenter.java +++ b/src/main/java/course_creation_use_case/CourseCreationPresenter.java @@ -7,14 +7,14 @@ Done? i guess */ -public interface courseCreationPresenter { +public interface CourseCreationPresenter { /* when course is successfully created */ - courseCreationResponseModel prepareSuccessView(courseCreationResponseModel newCourse); + CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel newCourse); /* when course name and instructor (courseID) already exists */ - courseCreationResponseModel prepareFailView(String error); + CourseCreationResponseModel prepareFailView(String error); } diff --git a/src/main/java/course_creation_use_case/courseCreationRequestModel.java b/src/main/java/course_creation_use_case/CourseCreationRequestModel.java similarity index 92% rename from src/main/java/course_creation_use_case/courseCreationRequestModel.java rename to src/main/java/course_creation_use_case/CourseCreationRequestModel.java index 8a45e33..5198be7 100644 --- a/src/main/java/course_creation_use_case/courseCreationRequestModel.java +++ b/src/main/java/course_creation_use_case/CourseCreationRequestModel.java @@ -12,13 +12,13 @@ import java.util.ArrayList; -public class courseCreationRequestModel { +public class CourseCreationRequestModel { private String courseName; private String courseInstructor; private final String courseID; private ArrayList tasks; - public courseCreationRequestModel(String courseName, String courseInstructor, ArrayList tasks) { + public CourseCreationRequestModel(String courseName, String courseInstructor, ArrayList tasks) { this.courseName = courseName; this.courseInstructor = courseInstructor; this.courseID = courseName + courseInstructor; diff --git a/src/main/java/course_creation_use_case/courseCreationResponseModel.java b/src/main/java/course_creation_use_case/CourseCreationResponseModel.java similarity index 92% rename from src/main/java/course_creation_use_case/courseCreationResponseModel.java rename to src/main/java/course_creation_use_case/CourseCreationResponseModel.java index 0465059..76ce0e0 100644 --- a/src/main/java/course_creation_use_case/courseCreationResponseModel.java +++ b/src/main/java/course_creation_use_case/CourseCreationResponseModel.java @@ -10,13 +10,13 @@ - do NOT depend on anything NOR have any references to Entity objects: violates SRP */ -public class courseCreationResponseModel { +public class CourseCreationResponseModel { // String courseName; // String instructorName; String courseID; ArrayList tasks; - public courseCreationResponseModel(String courseID, ArrayList tasks) { + public CourseCreationResponseModel(String courseID, ArrayList tasks) { this.courseID = courseID; this.tasks = tasks; } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java similarity index 67% rename from src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java rename to src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java index 0b95755..d35c274 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentDsGateway.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java @@ -2,10 +2,10 @@ // Use case layer -public interface courseEnrolmentDsGateway { +public interface CourseEnrolmentDsGateway { /* checks if student is in the course */ boolean existsByStudent(String studentIdentifier); // void saveStudent(courseEnrolmentDsRequestModel requestModel); - void saveStudent(courseEnrolmentRequestModel requestModel); + void saveStudent(CourseEnrolmentRequestModel requestModel); } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java new file mode 100644 index 0000000..1f38ba7 --- /dev/null +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java @@ -0,0 +1,10 @@ +package course_enrolment_use_case; + +// Use case layer + +/* +* DONE +* */ +public interface CourseEnrolmentInputBoundary { + CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestModel); +} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java similarity index 76% rename from src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java rename to src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java index 453838a..9e9b2b1 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentInteractor.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java @@ -2,19 +2,17 @@ // Use case layer -import Entities.CourseMap; +public class CourseEnrolmentInteractor implements CourseEnrolmentInputBoundary { + final CourseEnrolmentDsGateway courseEnrolmentDsGateway; + final CourseEnrolmentPresenter courseEnrolmentPresenter; -public class courseEnrolmentInteractor implements courseEnrolmentInputBoundary { - final courseEnrolmentDsGateway courseEnrolmentDsGateway; - final courseEnrolmentPresenter courseEnrolmentPresenter; - - public courseEnrolmentInteractor(courseEnrolmentDsGateway courseEnrolmentDsGateway, courseEnrolmentPresenter courseEnrolmentPresenter) { + public CourseEnrolmentInteractor(CourseEnrolmentDsGateway courseEnrolmentDsGateway, CourseEnrolmentPresenter courseEnrolmentPresenter) { this.courseEnrolmentDsGateway = courseEnrolmentDsGateway; this.courseEnrolmentPresenter = courseEnrolmentPresenter; } @Override - public courseEnrolmentResponseModel create(courseEnrolmentRequestModel requestModel) { + public CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestModel) { /* At least one info box left blank */ if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("")) { return courseEnrolmentPresenter.prepareFailView("Please fill in all required information." ); diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java similarity index 54% rename from src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java rename to src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java index ee100f1..6c771b7 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentPresenter.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java @@ -6,10 +6,10 @@ * Done? * */ -public interface courseEnrolmentPresenter { +public interface CourseEnrolmentPresenter { /* when course is found */ - courseEnrolmentResponseModel prepareSuccessView(courseEnrolmentResponseModel newStudent); + CourseEnrolmentResponseModel prepareSuccessView(CourseEnrolmentResponseModel newStudent); /* when course name and instructor combo not present in database*/ - courseEnrolmentResponseModel prepareFailView(String error); + CourseEnrolmentResponseModel prepareFailView(String error); } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java similarity index 87% rename from src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java rename to src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java index a17ab7b..c394d09 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentRequestModel.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java @@ -2,12 +2,12 @@ // Use case layer -public class courseEnrolmentRequestModel { +public class CourseEnrolmentRequestModel { private String courseName; private String courseInstructor; private final String courseID; - public courseEnrolmentRequestModel(String courseName, String courseInstructor) { + public CourseEnrolmentRequestModel(String courseName, String courseInstructor) { this.courseName = courseName; this.courseInstructor = courseInstructor; this.courseID = courseName + courseInstructor; diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java similarity index 85% rename from src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java rename to src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java index 6a2334e..923a23c 100644 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentResponseModel.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java @@ -2,7 +2,7 @@ import java.util.ArrayList; -public class courseEnrolmentResponseModel { +public class CourseEnrolmentResponseModel { String studentID; ArrayList tasks; // not sure if this goes here @@ -13,7 +13,7 @@ public class courseEnrolmentResponseModel { * @param studentID the ID corresponding to the StudentUser * @param tasks the tasks of the course */ - public courseEnrolmentResponseModel(String studentID, ArrayList tasks) { + public CourseEnrolmentResponseModel(String studentID, ArrayList tasks) { this.studentID = studentID; this.tasks = tasks; } diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java b/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java deleted file mode 100644 index 0a148e3..0000000 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentInputBoundary.java +++ /dev/null @@ -1,10 +0,0 @@ -package course_enrolment_use_case; - -// Use case layer - -/* -* DONE -* */ -public interface courseEnrolmentInputBoundary { - courseEnrolmentResponseModel create(courseEnrolmentRequestModel requestModel); -} diff --git a/src/main/java/screens/CourseCreationController.java b/src/main/java/screens/CourseCreationController.java index 633d20a..7c5efd8 100644 --- a/src/main/java/screens/CourseCreationController.java +++ b/src/main/java/screens/CourseCreationController.java @@ -1,20 +1,20 @@ package screens; -import course_creation_use_case.courseCreationInputBoundary; -import course_creation_use_case.courseCreationRequestModel; -import course_creation_use_case.courseCreationResponseModel; +import course_creation_use_case.CourseCreationInputBoundary; +import course_creation_use_case.CourseCreationRequestModel; +import course_creation_use_case.CourseCreationResponseModel; import java.util.ArrayList; public class CourseCreationController { - final courseCreationInputBoundary courseInput; - public CourseCreationController(courseCreationInputBoundary courseGateway) { + final CourseCreationInputBoundary courseInput; + public CourseCreationController(CourseCreationInputBoundary courseGateway) { this.courseInput = courseGateway; } - courseCreationResponseModel create(String courseName, String courseInstructor, + CourseCreationResponseModel create(String courseName, String courseInstructor, ArrayList tasks) { - courseCreationRequestModel requestModel = new courseCreationRequestModel( + CourseCreationRequestModel requestModel = new CourseCreationRequestModel( courseName, courseInstructor, tasks); return courseInput.create(requestModel); diff --git a/src/main/java/screens/CourseCreationResponseFormatter.java b/src/main/java/screens/CourseCreationResponseFormatter.java index 6e00fbb..b016475 100644 --- a/src/main/java/screens/CourseCreationResponseFormatter.java +++ b/src/main/java/screens/CourseCreationResponseFormatter.java @@ -2,19 +2,19 @@ // Interface adapters layer -import course_creation_use_case.courseCreationPresenter; -import course_creation_use_case.courseCreationResponseModel; +import course_creation_use_case.CourseCreationPresenter; +import course_creation_use_case.CourseCreationResponseModel; -public class CourseCreationResponseFormatter implements courseCreationPresenter { +public class CourseCreationResponseFormatter implements CourseCreationPresenter { @Override - public courseCreationResponseModel prepareSuccessView(courseCreationResponseModel response) { + public CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel response) { /* not sure what this is lol */ return response; } @Override - public courseCreationResponseModel prepareFailView(String error) { + public CourseCreationResponseModel prepareFailView(String error) { throw new CourseCreationFailed(error); } } diff --git a/src/main/java/screens/CourseEnrolmentController.java b/src/main/java/screens/CourseEnrolmentController.java index 6e2011e..89b96ef 100644 --- a/src/main/java/screens/CourseEnrolmentController.java +++ b/src/main/java/screens/CourseEnrolmentController.java @@ -1,17 +1,17 @@ package screens; -import course_enrolment_use_case.courseEnrolmentInputBoundary; -import course_enrolment_use_case.courseEnrolmentRequestModel; -import course_enrolment_use_case.courseEnrolmentResponseModel; +import course_enrolment_use_case.CourseEnrolmentInputBoundary; +import course_enrolment_use_case.CourseEnrolmentRequestModel; +import course_enrolment_use_case.CourseEnrolmentResponseModel; public class CourseEnrolmentController { - final courseEnrolmentInputBoundary enrolmentInput; - public CourseEnrolmentController(courseEnrolmentInputBoundary enrolmentGateway) { + final CourseEnrolmentInputBoundary enrolmentInput; + public CourseEnrolmentController(CourseEnrolmentInputBoundary enrolmentGateway) { this.enrolmentInput = enrolmentGateway; } - courseEnrolmentResponseModel create(String courseID, String instructorID) { - courseEnrolmentRequestModel requestModel = new courseEnrolmentRequestModel( + CourseEnrolmentResponseModel create(String courseID, String instructorID) { + CourseEnrolmentRequestModel requestModel = new CourseEnrolmentRequestModel( courseID, instructorID); return enrolmentInput.create(requestModel); diff --git a/src/main/java/screens/CourseEnrolmentResponseFormatter.java b/src/main/java/screens/CourseEnrolmentResponseFormatter.java index 6431cbb..ec0e1f6 100644 --- a/src/main/java/screens/CourseEnrolmentResponseFormatter.java +++ b/src/main/java/screens/CourseEnrolmentResponseFormatter.java @@ -2,19 +2,19 @@ // Interfaces adapters layer -import course_enrolment_use_case.courseEnrolmentPresenter; -import course_enrolment_use_case.courseEnrolmentResponseModel; +import course_enrolment_use_case.CourseEnrolmentPresenter; +import course_enrolment_use_case.CourseEnrolmentResponseModel; -public class CourseEnrolmentResponseFormatter implements courseEnrolmentPresenter { +public class CourseEnrolmentResponseFormatter implements CourseEnrolmentPresenter { @Override - public courseEnrolmentResponseModel prepareSuccessView(courseEnrolmentResponseModel response) { + public CourseEnrolmentResponseModel prepareSuccessView(CourseEnrolmentResponseModel response) { /* what is this */ return response; } @Override - public courseEnrolmentResponseModel prepareFailView(String error) { + public CourseEnrolmentResponseModel prepareFailView(String error) { throw new CourseEnrolmentFailed(error); } } diff --git a/src/main/java/screens/CourseFoundScreen.java b/src/main/java/screens/CourseFoundScreen.java new file mode 100644 index 0000000..369c132 --- /dev/null +++ b/src/main/java/screens/CourseFoundScreen.java @@ -0,0 +1,42 @@ +package screens; + +// Framework/Driver layer + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class CourseFoundScreen extends JFrame implements ActionListener { + /** + * Window with title and 2 JButtons. + */ + public CourseFoundScreen() { + JLabel title = new JLabel("Course Found!"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + + JButton cancel = new JButton("Cancel"); + JButton enrol = new JButton("Enrol"); + + JPanel buttons = new JPanel(); + buttons.add(cancel); + buttons.add(enrol); + + cancel.addActionListener(this); + enrol.addActionListener(this); + + JPanel main = new JPanel(); + main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); + + main.add(title); + main.add(buttons); + this.setContentPane(main); + this.pack(); + } + + /** + * react to button click that results in evt. */ + public void actionPerformed(ActionEvent evt) { + System.out.println("Click " + evt.getActionCommand()); + } +} diff --git a/src/main/java/screens/CreateCourseScreen.java b/src/main/java/screens/CreateCourseScreen.java index 3df5e26..f338bf5 100644 --- a/src/main/java/screens/CreateCourseScreen.java +++ b/src/main/java/screens/CreateCourseScreen.java @@ -14,15 +14,19 @@ public class CreateCourseScreen extends JPanel implements ActionListener { /** the course instructor */ JTextField courseInstructor = new JTextField(15); - /** the part i don't understand ... tasks .... */ -// JList tasks = new JList(15); + /* the part i don't understand ... tasks .... */ + /** title of task */ + JTextField taskName = new JTextField(25); + + /** id? of task */ + JTextField taskID = new JTextField(25); /** the controller */ CourseCreationController courseCreationController; /** - * A window with a title and JButton */ + * A window with a title, texts to fill in, and JButtons */ public CreateCourseScreen(CourseCreationController controller) { this.courseCreationController = controller; @@ -33,6 +37,10 @@ public CreateCourseScreen(CourseCreationController controller) { new JLabel("Enter course name"), courseName); LabelTextPanel courseInstructorInfo = new LabelTextPanel( new JLabel("Enter instructor name"), courseInstructor); + LabelTextPanel taskNameInfo = new LabelTextPanel( + new JLabel("Enter task title"), taskName); + LabelTextPanel taskIDInfo = new LabelTextPanel( + new JLabel("Enter task id"), taskID); JButton cancel = new JButton("Cancel"); JButton save = new JButton("Save"); @@ -49,8 +57,9 @@ public CreateCourseScreen(CourseCreationController controller) { this.add(title); this.add(courseNameInfo); this.add(courseInstructorInfo); + this.add(taskNameInfo); + this.add(taskIDInfo); this.add(buttons); - } /** @@ -59,12 +68,17 @@ public CreateCourseScreen(CourseCreationController controller) { public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); + /** why no work :,( try { + courseCreationController.create(courseName.getText(), + courseInstructor.getText(), taskName.getText(), taskID.getText()); + JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); // courseCreationController.create(courseName.getText(), // courseInstructor.getText(), tasks.getText()); // JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage()); } + */ } } diff --git a/src/main/java/screens/FileCourse.java b/src/main/java/screens/FileCourse.java index 1c743ef..858b0ac 100644 --- a/src/main/java/screens/FileCourse.java +++ b/src/main/java/screens/FileCourse.java @@ -1,8 +1,8 @@ package screens; -import course_creation_use_case.courseCreationDsGateway; +import course_creation_use_case.CourseCreationDsGateway; //import course_creation_use_case.courseCreationDsRequestModel; -import course_creation_use_case.courseCreationRequestModel; +import course_creation_use_case.CourseCreationRequestModel; /* * Notes: @@ -13,10 +13,10 @@ import java.util.HashMap; import java.util.Map; -public class FileCourse implements courseCreationDsGateway { +public class FileCourse implements CourseCreationDsGateway { private final File csvFile; private final Map headers = new HashMap<>(); - private final Map courses = new HashMap<>(); + private final Map courses = new HashMap<>(); public FileCourse(String csvPath) throws IOException { csvFile = new File(csvPath); @@ -39,7 +39,7 @@ public FileCourse(String csvPath) throws IOException { String courseInstructor = String.valueOf(col[headers.get("courseInstructor")]); ArrayList tasks = new ArrayList(); // idk what im doing // /* String.valueOf(col[headers.get("tasks?")]); */ - courseCreationRequestModel course = new courseCreationRequestModel(courseName, courseInstructor, tasks); + CourseCreationRequestModel course = new CourseCreationRequestModel(courseName, courseInstructor, tasks); courses.put(courseName, course); } @@ -54,7 +54,7 @@ public FileCourse(String csvPath) throws IOException { * @param requestModel the user information to save */ @Override - public void saveCourse(courseCreationRequestModel requestModel) { + public void saveCourse(CourseCreationRequestModel requestModel) { courses.put(requestModel.getCourseName() ,requestModel); this.saveCourse(); } @@ -66,7 +66,7 @@ private void saveCourse() { writer.write(String.join(",", headers.keySet())); writer.newLine(); - for (courseCreationRequestModel course : courses.values()) { + for (CourseCreationRequestModel course : courses.values()) { String line = "%s,%s,%s".format( course.getCourseName(), course.getCourseInstructor(), course.getTasks()); writer.write(line); diff --git a/src/main/java/screens/InMemoryCourse.java b/src/main/java/screens/InMemoryCourse.java index 6cd8b6e..e23eb00 100644 --- a/src/main/java/screens/InMemoryCourse.java +++ b/src/main/java/screens/InMemoryCourse.java @@ -1,15 +1,15 @@ package screens; -import course_creation_use_case.courseCreationDsGateway; +import course_creation_use_case.CourseCreationDsGateway; //import course_creation_use_case.courseCreationDsRequestModel; -import course_creation_use_case.courseCreationRequestModel; +import course_creation_use_case.CourseCreationRequestModel; import java.util.HashMap; import java.util.Map; -public class InMemoryCourse implements courseCreationDsGateway { - final private Map courses = new HashMap<>(); +public class InMemoryCourse implements CourseCreationDsGateway { + final private Map courses = new HashMap<>(); /** * @param identifier the course's course id @@ -24,7 +24,7 @@ public boolean existsByCourseID(String identifier) { * @param requestModel the data to save */ @Override - public void saveCourse(courseCreationRequestModel requestModel) { + public void saveCourse(CourseCreationRequestModel requestModel) { System.out.println("Save " + requestModel.getCourseID()); } } From af6175c0a35cee559d2f08f6033cc5029917b9ed Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 13:31:49 -0500 Subject: [PATCH 11/22] fixed course creation interactor --- src/main/java/Main.java | 75 +++++++++---------- .../CourseCreationInteractor.java | 58 +++----------- .../CourseCreationRequestModel.java | 2 - .../CourseEnrolmentInteractor.java | 15 +++- src/main/java/screens/CreateCourseScreen.java | 9 ++- 5 files changed, 65 insertions(+), 94 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index df563ec..e5ba988 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,17 +1,48 @@ //import Entities.CourseFactory; +import Entities.Course; import Entities.CourseMap; -import course_creation_use_case.CourseCreationDsGateway; -import course_creation_use_case.CourseCreationInputBoundary; -import course_creation_use_case.CourseCreationInteractor; -import course_creation_use_case.CourseCreationPresenter; +import course_creation_use_case.*; import screens.*; import javax.swing.*; import java.awt.*; import java.io.IOException; +import java.util.ArrayList; public class Main { + /** course creation screen */ + public static void main(String[] args) { + + // build main program window + JFrame application = new JFrame("Course Creation Example"); + CardLayout cardLayout = new CardLayout(); + JPanel screens = new JPanel(cardLayout); + application.add(screens); + + /** create parts to plug into the use case + entities engine -- not csv file */ + CourseCreationDsGateway course; + try { + course = new FileCourse("./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 + ); + + // COURSE CREATION build the GUI, plugging in the parts + CreateCourseScreen createCourseScreen = new CreateCourseScreen(courseCreationController); + screens.add(createCourseScreen, "create a new course"); + cardLayout.show(screens, "create course"); + application.pack(); + application.setVisible(true); + } + // public static void main(String[] args) { // // /** build main program window */ @@ -42,40 +73,4 @@ public class Main { // application.setVisible(true); // // } - -// /** course creation screen - public static void main(String[] args) { - - // build main program window - JFrame application = new JFrame("Course Creation Example"); - CardLayout cardLayout = new CardLayout(); - JPanel screens = new JPanel(cardLayout); - application.add(screens); - - // create parts to plug into the use case + entities engine - CourseCreationDsGateway course; - try { - course = new FileCourse("./courses.csv"); - } catch (IOException e) { - throw new RuntimeException("Could not create file."); - } - CourseCreationPresenter presenter = new CourseCreationResponseFormatter(); - CourseMap courseMap = new CourseMap(); - -// CourseFactory courseFactory = new CourseFactory(); - - CourseCreationInputBoundary interactor = new CourseCreationInteractor( - course, presenter, courseMap); - CourseCreationController courseCreationController = new CourseCreationController( - interactor - ); - - // COURSE CREATION build the GUI, plugging in the parts - CreateCourseScreen createCourseScreen = new CreateCourseScreen(courseCreationController); - screens.add(createCourseScreen, "create a new course"); - cardLayout.show(screens, "create course"); - application.pack(); - application.setVisible(true); - - } } diff --git a/src/main/java/course_creation_use_case/CourseCreationInteractor.java b/src/main/java/course_creation_use_case/CourseCreationInteractor.java index 85da0de..f09d202 100644 --- a/src/main/java/course_creation_use_case/CourseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/CourseCreationInteractor.java @@ -2,25 +2,11 @@ // Use case layer -/* Notes -VERY CONFUSED --> NEED COURSE FACTORY? -- ok i think the problem is i need to decide how to store date: - 1. csv file with rows (i want, but how to store courseID as well?) - 2. coursefactory ???? whatever that is - 3. courseMAp ...... not really useful for me? - - and problemo is: which one of them is persistent / serializable? - -** the class that runs the use case (subclass of input boundary) -the highest level concept; the most protected - */ - -//import Entities.CourseFactory; -import Entities.CourseMap; +import Entities.*; public class CourseCreationInteractor implements CourseCreationInputBoundary { final CourseCreationDsGateway courseCreationDSGateway; final CourseCreationPresenter courseCreationPresenter; -// final CourseFactory courseFactory; final CourseMap courseMap; public CourseCreationInteractor(CourseCreationDsGateway courseCreationDSGateway, CourseCreationPresenter courseCreationPresenter, @@ -30,13 +16,6 @@ public CourseCreationInteractor(CourseCreationDsGateway courseCreationDSGateway, this.courseMap = courseMap; } -// public courseCreationInteractor(courseCreationDsGateway courseCreationDSGateway, courseCreationPresenter courseCreationPresenter, -// CourseFactory courseFactory) { -// this.courseCreationDSGateway = courseCreationDSGateway; -// this.courseCreationPresenter = courseCreationPresenter; -// this.courseFactory = courseFactory; -// } - @Override public CourseCreationResponseModel create(CourseCreationRequestModel requestModel) { /* At least one info box left blank */ @@ -44,7 +23,7 @@ public CourseCreationResponseModel create(CourseCreationRequestModel requestMode return courseCreationPresenter.prepareFailView("Please fill in all required information."); } /* - Note: no need to check if is instructor; users would have different + Note: Jonathan - no need to check if is instructor; users would have different views because they are in different use cases If the course id (same course name and instructor name) already exists, new course will not be made. @@ -53,34 +32,19 @@ If the course id (same course name and instructor name) already exists, new if (courseCreationDSGateway.existsByCourseID(requestModel.getCourseID())) { return courseCreationPresenter.prepareFailView("Course already exists."); } - return null; - - /* - * what is a courseFactory - */ - /** confused lol - Course course = CourseMap.addCourse(requestModel.getCourseID(), course); - Course course1 = CourseMap.addCourse(requestModel.getCourseID(), requestModel.getTasks()); - */ + /* create new course */ + Course course = new Course(requestModel.getCourseName(), requestModel.getCourseInstructor(), requestModel.getTasks()); + CourseMap.addCourse(requestModel.getCourseID(), course); - /** checks passed, course successfully created and saved - courseCreationRequestModel courseCreationModel = new courseCreationRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); + /* checks passed, course successfully created and saved */ + CourseCreationRequestModel courseCreationModel = new CourseCreationRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); courseCreationDSGateway.saveCourse(courseCreationModel); -// courseCreationDSRequestModel courseCreationDSModel = new courseCreationDSRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); -// courseCreationDSGateway.saveCourse(courseCreationDSModel); - */ -// - /** checks passed, course sent to presenter */ -// courseCreationResponseModel courseResponseModel = new courseCreationResponseModel( -// course.getCourseID(), course.getTasks()); -// return courseCreationPresenter.prepareSuccessView(courseResponseModel); + /* checks passed, course sent to presenter */ + CourseCreationResponseModel courseResponseModel = new CourseCreationResponseModel( + course.getCourseID(), course.getTasks()); + return courseCreationPresenter.prepareSuccessView(courseResponseModel); - /** - * below is not it */ -// courseCreationResponseModel courseResponseModel = new courseCreationResponseModel( -// course.getCourseID(), course.getTasks()); -// return courseCreationPresenter.prepareFailViewSuccessView(courseResponseModel); } } diff --git a/src/main/java/course_creation_use_case/CourseCreationRequestModel.java b/src/main/java/course_creation_use_case/CourseCreationRequestModel.java index 5198be7..ad37b47 100644 --- a/src/main/java/course_creation_use_case/CourseCreationRequestModel.java +++ b/src/main/java/course_creation_use_case/CourseCreationRequestModel.java @@ -25,8 +25,6 @@ public CourseCreationRequestModel(String courseName, String courseInstructor, Ar this.tasks = tasks; } - /** - * all getters changed to public, used by FileCourse */ public String getCourseName() { return courseName; } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java index 9e9b2b1..a00405f 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java @@ -1,7 +1,13 @@ package course_enrolment_use_case; + // Use case layer +import Entities.Course; +import Entities.CourseMap; +import course_creation_use_case.CourseCreationRequestModel; +import course_creation_use_case.CourseCreationResponseModel; + public class CourseEnrolmentInteractor implements CourseEnrolmentInputBoundary { final CourseEnrolmentDsGateway courseEnrolmentDsGateway; final CourseEnrolmentPresenter courseEnrolmentPresenter; @@ -19,7 +25,7 @@ public CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestMo /* map is courseid --> Course * checks if given course id is in the map of existing courses*/ } -// else if (!CourseMap.containsKey(requestModel.getCourseID())) { +// else if (!CourseMap.addCourse(requestModel.getCourseID())) { // return courseEnrolmentPresenter.prepareFailView("Entered information does not correspond to an existing course."); // } @@ -32,7 +38,12 @@ public CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestMo // return courseEnrolmentPresenter.prepareFailView("Already enrolled in course."); // } + /* + add student id to courses' list of students + update + save coursemap edits + success view to presenter + */ + return null; } - } diff --git a/src/main/java/screens/CreateCourseScreen.java b/src/main/java/screens/CreateCourseScreen.java index f338bf5..509a01c 100644 --- a/src/main/java/screens/CreateCourseScreen.java +++ b/src/main/java/screens/CreateCourseScreen.java @@ -6,6 +6,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; public class CreateCourseScreen extends JPanel implements ActionListener { /** the course name chosen by InstructorUser */ @@ -68,10 +69,12 @@ public CreateCourseScreen(CourseCreationController controller) { public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); - /** why no work :,( + /** why no work :,( */ try { + ArrayList task = new ArrayList(); + task.add("taskid"); courseCreationController.create(courseName.getText(), - courseInstructor.getText(), taskName.getText(), taskID.getText()); + courseInstructor.getText(), task); // third argument should be taskName.getText() JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); // courseCreationController.create(courseName.getText(), // courseInstructor.getText(), tasks.getText()); @@ -79,6 +82,6 @@ public void actionPerformed(ActionEvent evt) { } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage()); } - */ + } } From e0e2f725f7fb07f0520c2a59a34ade31ef684232 Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 15:31:35 -0500 Subject: [PATCH 12/22] deleted unnecessary files --- .../courseCreationDsRequestModel.java | 40 ------------------- .../courseEnrolmentDsRequestModel.java | 23 ----------- src/main/java/screens/InMemoryCourse.java | 22 ---------- 3 files changed, 85 deletions(-) delete mode 100644 src/main/java/course_creation_use_case/courseCreationDsRequestModel.java delete mode 100644 src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java diff --git a/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java b/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java deleted file mode 100644 index 4f8cb5f..0000000 --- a/src/main/java/course_creation_use_case/courseCreationDsRequestModel.java +++ /dev/null @@ -1,40 +0,0 @@ -//package course_creation_use_case; -// -//// Use case layer -// -//// Notes: -//// DONE? ACTUALLY NOT EVEN NEEDED????? -// -// -//import java.util.ArrayList; -// -//public class courseCreationDsRequestModel { -// private final String courseName; -// private final String courseInstructor; -// private final String courseID; -// private ArrayList tasks; -// -// public courseCreationDsRequestModel(String courseName, String courseInstructor, ArrayList tasks) { -// this.courseName = courseName; -// this.courseInstructor = courseInstructor; -// this.courseID = courseName + courseInstructor; -// this.tasks = tasks; -// } -// -// public String getCourseName() { -// return courseName; -// } -// public String getCourseInstructor() { -// return courseInstructor; -// } -// public String getCourseID() { -// return courseID; -// } -// public ArrayList getTasks() { -// return tasks; -// } -// -// public void setTasks(ArrayList tasks) { -// this.tasks = tasks; -// } -//} diff --git a/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java b/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java deleted file mode 100644 index a329f4f..0000000 --- a/src/main/java/course_enrolment_use_case/courseEnrolmentDsRequestModel.java +++ /dev/null @@ -1,23 +0,0 @@ -//package course_enrolment_use_case; -// -//public class courseEnrolmentDssRequestModel { -// private final String courseName; -// private final String courseInstructor; -// private final String courseID; // searches using this -// -// public courseEnrolmentDsRequestModel(String courseName, String courseInstructor) { -// this.courseName = courseName; -// this.courseInstructor = courseInstructor; -// this.courseID = courseName + courseInstructor; -// } -// -// public String getCourseName() { -// return courseName; -// } -// public String getCourseInstructor() { -// return courseInstructor; -// } -// public String getCourseID() { -// return courseID; -// } -//} diff --git a/src/main/java/screens/InMemoryCourse.java b/src/main/java/screens/InMemoryCourse.java index e23eb00..70f14b2 100644 --- a/src/main/java/screens/InMemoryCourse.java +++ b/src/main/java/screens/InMemoryCourse.java @@ -1,7 +1,6 @@ package screens; import course_creation_use_case.CourseCreationDsGateway; -//import course_creation_use_case.courseCreationDsRequestModel; import course_creation_use_case.CourseCreationRequestModel; @@ -28,24 +27,3 @@ public void saveCourse(CourseCreationRequestModel requestModel) { System.out.println("Save " + requestModel.getCourseID()); } } - -//public class InMemoryCourse implements courseCreationDsGateway { -// final private Map courses = new HashMap<>(); -// -// /** -// * @param identifier the course's course id -// * @return whether the course exists -// */ -// @Override -// public boolean existsByCourseID(String identifier) { -// return courses.containsKey(identifier); -// } -// -// /** -// * @param requestModel the data to save -// */ -// @Override -// public void saveCourse(courseCreationDsRequestModel requestModel) { -// System.out.println("Save " + requestModel.getCourseID()); -// } -//} From f92b2ceba1d1084f3b9222eacf4e1ef666bc6c36 Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 15:32:27 -0500 Subject: [PATCH 13/22] deleted unnecessary file --- src/main/java/Entities/CourseFactory.java | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/main/java/Entities/CourseFactory.java diff --git a/src/main/java/Entities/CourseFactory.java b/src/main/java/Entities/CourseFactory.java deleted file mode 100644 index b6d5d39..0000000 --- a/src/main/java/Entities/CourseFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -//package Entities; -// -//// Entity layer -// -//import java.util.ArrayList; -// -//public class CourseFactory { -// public Course create(String courseName, String courseInstructor, ArrayList tasks) { -// return new Course(courseName, courseInstructor, tasks); -// } -//} -/** - * no longer needed! just for if you need to work with different types of users - */ \ No newline at end of file From 2f2d84eb18247bd97576b56463fce666d52c490e Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 16:07:18 -0500 Subject: [PATCH 14/22] empty use case 3 (task to task list) files --- .../TaskToTasklistInteractor.java | 4 ++++ .../TaskToTasklistPresenter.java | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java create mode 100644 src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistPresenter.java diff --git a/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java b/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java new file mode 100644 index 0000000..5aa7832 --- /dev/null +++ b/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java @@ -0,0 +1,4 @@ +package tasks_to_student_tasklist_use_case; + +public class TaskToTasklistInteractor { +} diff --git a/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistPresenter.java b/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistPresenter.java new file mode 100644 index 0000000..66f3c46 --- /dev/null +++ b/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistPresenter.java @@ -0,0 +1,4 @@ +package tasks_to_student_tasklist_use_case; + +public interface TaskToTasklistPresenter { +} From 7bdb5314f37c2d809f5332e71cebd755c4dabe70 Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 16:18:56 -0500 Subject: [PATCH 15/22] minor changes to main --- src/main/java/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e5ba988..09f4a5b 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,4 +1,3 @@ -//import Entities.CourseFactory; import Entities.Course; import Entities.CourseMap; import course_creation_use_case.*; From 87e06fa8774f6d43014499c60d8707008f3e7b17 Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 16:22:56 -0500 Subject: [PATCH 16/22] removed main file so that it wouldn't push to pr branch --- src/main/java/Main.java | 75 ----------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 src/main/java/Main.java diff --git a/src/main/java/Main.java b/src/main/java/Main.java deleted file mode 100644 index 09f4a5b..0000000 --- a/src/main/java/Main.java +++ /dev/null @@ -1,75 +0,0 @@ -import Entities.Course; -import Entities.CourseMap; -import course_creation_use_case.*; -import screens.*; - -import javax.swing.*; -import java.awt.*; -import java.io.IOException; -import java.util.ArrayList; - -public class Main { - - /** course creation screen */ - public static void main(String[] args) { - - // build main program window - JFrame application = new JFrame("Course Creation Example"); - CardLayout cardLayout = new CardLayout(); - JPanel screens = new JPanel(cardLayout); - application.add(screens); - - /** create parts to plug into the use case + entities engine -- not csv file */ - CourseCreationDsGateway course; - try { - course = new FileCourse("./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 - ); - - // COURSE CREATION build the GUI, plugging in the parts - CreateCourseScreen createCourseScreen = new CreateCourseScreen(courseCreationController); - screens.add(createCourseScreen, "create a new course"); - cardLayout.show(screens, "create course"); - application.pack(); - application.setVisible(true); - } - -// public static void main(String[] args) { -// -// /** build main program window */ -// JFrame application = new JFrame("Course Enrolment Example"); -// CardLayout cardLayout = new CardLayout(); -// JPanel screens = new JPanel(cardLayout); -// application.add(screens); -// -// /** create parts to plug into the use case + entities engine */ -// courseEnrolmentDsGateway course = new Course(CourseMap.addCourse()); -//// try { -//// course = new FileCourse("./courses.csv"); -//// } catch (IOException e) { -//// throw new RuntimeException("Could not create file."); -//// } -// courseEnrolmentPresenter presenter = new CourseEnrolmentResponseFormatter(); -// courseEnrolmentInputBoundary interactor = new courseEnrolmentInteractor( -// course, presenter); -// CourseEnrolmentController courseEnrolmentController = new CourseEnrolmentController( -// interactor -// ); -// -// // COURSE ENROLMENT build the GUI, plugging in the parts -// CourseEnrolmentScreen courseEnrolmentScreen = new CourseEnrolmentScreen(courseEnrolmentController); -// screens.add(courseEnrolmentScreen, "enter course name"); -// cardLayout.show(screens, "enrol in course"); -// application.pack(); -// application.setVisible(true); -// -// } -} From 703bf4be43f1ecf9a6b206a99e5e48987fdc5ecb Mon Sep 17 00:00:00 2001 From: jltng Date: Sat, 19 Nov 2022 16:53:09 -0500 Subject: [PATCH 17/22] renamed entities package to proper java naming convention, commented out test file --- .../CourseCreationInteractor.java | 2 +- .../CourseEnrolmentInteractor.java | 5 ---- .../{Entities => entities}/Assignment.java | 2 +- .../java/{Entities => entities}/Course.java | 2 +- .../{Entities => entities}/CourseMap.java | 2 +- .../java/{Entities => entities}/Event.java | 2 +- .../java/{Entities => entities}/Gradable.java | 2 +- src/main/java/entities/InstructorUser.java | 3 +- src/main/java/entities/StudentUser.java | 2 +- .../java/{Entities => entities}/Task.java | 2 +- .../java/{Entities => entities}/Test.java | 2 +- .../{Entities => entities}/Timeblockable.java | 2 +- src/main/java/entities/User.java | 2 +- src/main/java/entities/UserWhisperer.java | 22 --------------- src/main/java/entities/internalUserList.java | 17 ----------- test/entities/CourseUnitTest.java | 28 +++++++++---------- 16 files changed, 26 insertions(+), 71 deletions(-) rename src/main/java/{Entities => entities}/Assignment.java (99%) rename src/main/java/{Entities => entities}/Course.java (99%) rename src/main/java/{Entities => entities}/CourseMap.java (98%) rename src/main/java/{Entities => entities}/Event.java (99%) rename src/main/java/{Entities => entities}/Gradable.java (94%) rename src/main/java/{Entities => entities}/Task.java (99%) rename src/main/java/{Entities => entities}/Test.java (99%) rename src/main/java/{Entities => entities}/Timeblockable.java (97%) delete mode 100644 src/main/java/entities/UserWhisperer.java delete mode 100644 src/main/java/entities/internalUserList.java diff --git a/src/main/java/course_creation_use_case/CourseCreationInteractor.java b/src/main/java/course_creation_use_case/CourseCreationInteractor.java index f09d202..4d9138b 100644 --- a/src/main/java/course_creation_use_case/CourseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/CourseCreationInteractor.java @@ -2,7 +2,7 @@ // Use case layer -import Entities.*; +import entities.*; public class CourseCreationInteractor implements CourseCreationInputBoundary { final CourseCreationDsGateway courseCreationDSGateway; diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java index a00405f..ce2a10f 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java @@ -3,11 +3,6 @@ // Use case layer -import Entities.Course; -import Entities.CourseMap; -import course_creation_use_case.CourseCreationRequestModel; -import course_creation_use_case.CourseCreationResponseModel; - public class CourseEnrolmentInteractor implements CourseEnrolmentInputBoundary { final CourseEnrolmentDsGateway courseEnrolmentDsGateway; final CourseEnrolmentPresenter courseEnrolmentPresenter; diff --git a/src/main/java/Entities/Assignment.java b/src/main/java/entities/Assignment.java similarity index 99% rename from src/main/java/Entities/Assignment.java rename to src/main/java/entities/Assignment.java index 8a7b4d7..460621b 100644 --- a/src/main/java/Entities/Assignment.java +++ b/src/main/java/entities/Assignment.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.time.LocalDateTime; public class Assignment extends Task implements Gradable { diff --git a/src/main/java/Entities/Course.java b/src/main/java/entities/Course.java similarity index 99% rename from src/main/java/Entities/Course.java rename to src/main/java/entities/Course.java index a68ec2b..a04034b 100644 --- a/src/main/java/Entities/Course.java +++ b/src/main/java/entities/Course.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.util.ArrayList; diff --git a/src/main/java/Entities/CourseMap.java b/src/main/java/entities/CourseMap.java similarity index 98% rename from src/main/java/Entities/CourseMap.java rename to src/main/java/entities/CourseMap.java index 3db8dce..4af1054 100644 --- a/src/main/java/Entities/CourseMap.java +++ b/src/main/java/entities/CourseMap.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.io.Serializable; import java.util.HashMap; diff --git a/src/main/java/Entities/Event.java b/src/main/java/entities/Event.java similarity index 99% rename from src/main/java/Entities/Event.java rename to src/main/java/entities/Event.java index c4d1d8e..408545b 100644 --- a/src/main/java/Entities/Event.java +++ b/src/main/java/entities/Event.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.time.LocalDateTime; public class Event extends Task implements Timeblockable { diff --git a/src/main/java/Entities/Gradable.java b/src/main/java/entities/Gradable.java similarity index 94% rename from src/main/java/Entities/Gradable.java rename to src/main/java/entities/Gradable.java index 7c686e3..97cd78c 100644 --- a/src/main/java/Entities/Gradable.java +++ b/src/main/java/entities/Gradable.java @@ -1,4 +1,4 @@ -package Entities; +package entities; public interface Gradable { /** diff --git a/src/main/java/entities/InstructorUser.java b/src/main/java/entities/InstructorUser.java index ff6f66d..d386c15 100644 --- a/src/main/java/entities/InstructorUser.java +++ b/src/main/java/entities/InstructorUser.java @@ -1,7 +1,6 @@ -package Entities; +package entities; import java.util.ArrayList; -import java.util.List; public class InstructorUser extends User { diff --git a/src/main/java/entities/StudentUser.java b/src/main/java/entities/StudentUser.java index 761b05d..102074a 100644 --- a/src/main/java/entities/StudentUser.java +++ b/src/main/java/entities/StudentUser.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.time.LocalDateTime; import java.util.*; diff --git a/src/main/java/Entities/Task.java b/src/main/java/entities/Task.java similarity index 99% rename from src/main/java/Entities/Task.java rename to src/main/java/entities/Task.java index cd6606f..7d271e2 100644 --- a/src/main/java/Entities/Task.java +++ b/src/main/java/entities/Task.java @@ -1,4 +1,4 @@ -package Entities; +package entities; public abstract class Task { private String title; diff --git a/src/main/java/Entities/Test.java b/src/main/java/entities/Test.java similarity index 99% rename from src/main/java/Entities/Test.java rename to src/main/java/entities/Test.java index 05698fd..e8f8535 100644 --- a/src/main/java/Entities/Test.java +++ b/src/main/java/entities/Test.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.time.LocalDateTime; diff --git a/src/main/java/Entities/Timeblockable.java b/src/main/java/entities/Timeblockable.java similarity index 97% rename from src/main/java/Entities/Timeblockable.java rename to src/main/java/entities/Timeblockable.java index 1e0d0e7..193664b 100644 --- a/src/main/java/Entities/Timeblockable.java +++ b/src/main/java/entities/Timeblockable.java @@ -1,4 +1,4 @@ -package Entities; +package entities; import java.time.LocalDateTime; public interface Timeblockable { /** diff --git a/src/main/java/entities/User.java b/src/main/java/entities/User.java index f6a0b05..85a510f 100644 --- a/src/main/java/entities/User.java +++ b/src/main/java/entities/User.java @@ -1,4 +1,4 @@ -package Entities; +package entities; // Entity public abstract class User { diff --git a/src/main/java/entities/UserWhisperer.java b/src/main/java/entities/UserWhisperer.java deleted file mode 100644 index 0f29fe5..0000000 --- a/src/main/java/entities/UserWhisperer.java +++ /dev/null @@ -1,22 +0,0 @@ -package Entities; - -// Entity - -public class UserWhisperer { - - /** Entity Layer - * What this class does */ - - public StudentUser createStudent(String name, String password) { - return new StudentUser(name, password); - } - - public InstructorUser createInstructor(String name, String password) { - return null; - } - - - public String SearchUser(String name) { - return null; - } -} diff --git a/src/main/java/entities/internalUserList.java b/src/main/java/entities/internalUserList.java deleted file mode 100644 index ccd5879..0000000 --- a/src/main/java/entities/internalUserList.java +++ /dev/null @@ -1,17 +0,0 @@ -package Entities; - -import java.util.ArrayList; - -public class internalUserList { - - /** Entity Layer - * An internal list of all Users of this program */ - - private ArrayList UserList; - - public String getUser(String userid) { - return null; - } - - public void addUser() {} -} diff --git a/test/entities/CourseUnitTest.java b/test/entities/CourseUnitTest.java index 25b1a21..bbcbc7f 100644 --- a/test/entities/CourseUnitTest.java +++ b/test/entities/CourseUnitTest.java @@ -1,16 +1,16 @@ package entities; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -import Entities.Course; -public class CourseUnitTest { - - @Test - void givenCourse_whenCourseExists_thenIsFalse() { - Course course = new Course("csc207", "abc", "tasks idk"); - - assertFalse(course.courseExists); - } -} +//import org.junit.jupiter.api.Test; +// +//import static org.junit.jupiter.api.Assertions.assertFalse; +// +//import entities.Course; +//public class CourseUnitTest { +// +// @Test +// void givenCourse_whenCourseExists_thenIsFalse() { +// Course course = new Course("csc207", "abc", "tasks idk"); +// +// assertFalse(course.courseExists); +// } +//} From da810e91fd65d63006319e121ab965fcac916724 Mon Sep 17 00:00:00 2001 From: jltng Date: Sun, 20 Nov 2022 20:26:26 -0500 Subject: [PATCH 18/22] course creation use case completed and documentation added (minus data persistence and tests) --- .../CourseCreationDsGateway.java | 4 -- .../CourseCreationInputBoundary.java | 1 - .../CourseCreationInteractor.java | 16 ++++-- .../CourseCreationPresenter.java | 16 +++--- .../CourseCreationRequestModel.java | 7 ++- .../CourseCreationResponseModel.java | 41 +++----------- .../CourseCreationResponseFormatter.java | 13 ++++- ...eScreen.java => CourseCreationScreen.java} | 56 +++++++++++-------- .../java/screens/CourseEnrolmentScreen.java | 2 +- 9 files changed, 76 insertions(+), 80 deletions(-) rename src/main/java/screens/{CreateCourseScreen.java => CourseCreationScreen.java} (53%) diff --git a/src/main/java/course_creation_use_case/CourseCreationDsGateway.java b/src/main/java/course_creation_use_case/CourseCreationDsGateway.java index 5ac9d5d..e6003bb 100644 --- a/src/main/java/course_creation_use_case/CourseCreationDsGateway.java +++ b/src/main/java/course_creation_use_case/CourseCreationDsGateway.java @@ -4,15 +4,11 @@ /* Notes: -DONE? - the methods the repo needs to implement for the interactor to do its job */ public interface CourseCreationDsGateway { -// boolean existsByCourseName(String courseIdentifier); -// boolean existsByInstructorName(String instructorIdentifier); boolean existsByCourseID(String courseIdentifier); -// void saveCourse(courseCreationDsRequestModel requestModel); void saveCourse(CourseCreationRequestModel requestModel); } diff --git a/src/main/java/course_creation_use_case/CourseCreationInputBoundary.java b/src/main/java/course_creation_use_case/CourseCreationInputBoundary.java index afd1441..95d4426 100644 --- a/src/main/java/course_creation_use_case/CourseCreationInputBoundary.java +++ b/src/main/java/course_creation_use_case/CourseCreationInputBoundary.java @@ -5,7 +5,6 @@ /* Notes: - DONE - the public interface for calling the use case - boundaries are interfaces - input boundary is between the controller and use case diff --git a/src/main/java/course_creation_use_case/CourseCreationInteractor.java b/src/main/java/course_creation_use_case/CourseCreationInteractor.java index 4d9138b..5c09aae 100644 --- a/src/main/java/course_creation_use_case/CourseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/CourseCreationInteractor.java @@ -16,9 +16,14 @@ public CourseCreationInteractor(CourseCreationDsGateway courseCreationDSGateway, this.courseMap = courseMap; } + /** + * Creates the task in the request model and returns the corresponding response model + * @param requestModel the input from the return + */ @Override public CourseCreationResponseModel create(CourseCreationRequestModel requestModel) { - /* At least one info box left blank */ + + // At least one field left blank if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") || requestModel.getTasks().isEmpty()) { return courseCreationPresenter.prepareFailView("Please fill in all required information."); } @@ -33,18 +38,19 @@ If the course id (same course name and instructor name) already exists, new return courseCreationPresenter.prepareFailView("Course already exists."); } - /* create new course */ + // checks passed; course can be created + + // create a new course Course course = new Course(requestModel.getCourseName(), requestModel.getCourseInstructor(), requestModel.getTasks()); CourseMap.addCourse(requestModel.getCourseID(), course); - /* checks passed, course successfully created and saved */ + // course successfully created and saved CourseCreationRequestModel courseCreationModel = new CourseCreationRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); courseCreationDSGateway.saveCourse(courseCreationModel); - /* checks passed, course sent to presenter */ + // course sent to presenter CourseCreationResponseModel courseResponseModel = new CourseCreationResponseModel( course.getCourseID(), course.getTasks()); return courseCreationPresenter.prepareSuccessView(courseResponseModel); - } } diff --git a/src/main/java/course_creation_use_case/CourseCreationPresenter.java b/src/main/java/course_creation_use_case/CourseCreationPresenter.java index c35aae3..329d487 100644 --- a/src/main/java/course_creation_use_case/CourseCreationPresenter.java +++ b/src/main/java/course_creation_use_case/CourseCreationPresenter.java @@ -2,19 +2,17 @@ // Use case layer -/* -Notes: -Done? i guess - */ - public interface CourseCreationPresenter { - /* - when course is successfully created + + /** + * Alerts user that course creation is successful (no existing course) + * @param newCourse the output from the program */ CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel newCourse); - /* - when course name and instructor (courseID) already exists + /** + * Alerts user tht course creation attempted failed + * @param error the output from the program */ CourseCreationResponseModel prepareFailView(String error); } diff --git a/src/main/java/course_creation_use_case/CourseCreationRequestModel.java b/src/main/java/course_creation_use_case/CourseCreationRequestModel.java index ad37b47..80341f5 100644 --- a/src/main/java/course_creation_use_case/CourseCreationRequestModel.java +++ b/src/main/java/course_creation_use_case/CourseCreationRequestModel.java @@ -4,7 +4,6 @@ /* Notes: - DONE? - requests what is needed for its input data (what person in front of computer enters) - do NOT depend on anything NOR have any references to Entity objects: violates SRP */ @@ -18,6 +17,12 @@ public class CourseCreationRequestModel { private final String courseID; private ArrayList tasks; + /** + * Creates a request model with the given input + * @param courseName the name of the course + * @param courseInstructor the instructor of the course + * @param tasks the task(s) associated with the course + */ public CourseCreationRequestModel(String courseName, String courseInstructor, ArrayList tasks) { this.courseName = courseName; this.courseInstructor = courseInstructor; diff --git a/src/main/java/course_creation_use_case/CourseCreationResponseModel.java b/src/main/java/course_creation_use_case/CourseCreationResponseModel.java index 76ce0e0..68708ab 100644 --- a/src/main/java/course_creation_use_case/CourseCreationResponseModel.java +++ b/src/main/java/course_creation_use_case/CourseCreationResponseModel.java @@ -7,15 +7,18 @@ /* Notes: - the output data produced; returns the response as the output -- do NOT depend on anything NOR have any references to Entity objects: violates SRP +- does NOT depend on anything NOR should have any references to Entity objects: violates SRP */ public class CourseCreationResponseModel { -// String courseName; -// String instructorName; String courseID; ArrayList tasks; + /** + * Creates a response model for course creation use case + * @param courseID the unique id of the course being created + * @param tasks the task(s) associated with the course being created + */ public CourseCreationResponseModel(String courseID, ArrayList tasks) { this.courseID = courseID; this.tasks = tasks; @@ -30,39 +33,9 @@ public ArrayList getTasks() { return tasks; } - /* do not think this is needed: + // i don't think this is needed public void setTasks() { this.tasks = tasks; } - - public courseCreationResponseModel(String courseName, String instructorName) { - this.courseName = courseName; - this.instructorName = instructorName; - } - - public String getCourseName() { - return this.courseName; - } - - public void setCourseName() { - this.courseName = courseName; - } - - public String getInstructorName() { - return this.instructorName; - } - - public void setInstructorName() { - this.instructorName = instructorName; - } - - public ArrayList getTasks() { - return this.tasks; - } - - public void setTasks() { - this.tasks = tasks; - } - */ } diff --git a/src/main/java/screens/CourseCreationResponseFormatter.java b/src/main/java/screens/CourseCreationResponseFormatter.java index b016475..55b7e1f 100644 --- a/src/main/java/screens/CourseCreationResponseFormatter.java +++ b/src/main/java/screens/CourseCreationResponseFormatter.java @@ -5,14 +5,25 @@ import course_creation_use_case.CourseCreationPresenter; import course_creation_use_case.CourseCreationResponseModel; +import javax.swing.*; + public class CourseCreationResponseFormatter implements CourseCreationPresenter { + /** + * Alert user to course creation success + * @param response the output from the program + */ @Override public CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel response) { - /* not sure what this is lol */ + + JOptionPane.showMessageDialog(null, "New course created!"); return response; } + /** + * Alert user to course creation failure + * @param error the output from the program + */ @Override public CourseCreationResponseModel prepareFailView(String error) { throw new CourseCreationFailed(error); diff --git a/src/main/java/screens/CreateCourseScreen.java b/src/main/java/screens/CourseCreationScreen.java similarity index 53% rename from src/main/java/screens/CreateCourseScreen.java rename to src/main/java/screens/CourseCreationScreen.java index 509a01c..168ebb6 100644 --- a/src/main/java/screens/CreateCourseScreen.java +++ b/src/main/java/screens/CourseCreationScreen.java @@ -8,7 +8,7 @@ import java.awt.event.ActionListener; import java.util.ArrayList; -public class CreateCourseScreen extends JPanel implements ActionListener { +public class CourseCreationScreen extends JPanel implements ActionListener { /** the course name chosen by InstructorUser */ JTextField courseName = new JTextField(15); @@ -20,29 +20,32 @@ public class CreateCourseScreen extends JPanel implements ActionListener { /** title of task */ JTextField taskName = new JTextField(25); - /** id? of task */ - JTextField taskID = new JTextField(25); - /** the controller */ CourseCreationController courseCreationController; /** * A window with a title, texts to fill in, and JButtons */ - public CreateCourseScreen(CourseCreationController controller) { + public CourseCreationScreen(CourseCreationController controller) { this.courseCreationController = controller; + // label for the title of the screen JLabel title = new JLabel("Course Creation Screen"); title.setAlignmentX(Component.CENTER_ALIGNMENT); + // text fields for instructor to enter in required course info LabelTextPanel courseNameInfo = new LabelTextPanel( new JLabel("Enter course name"), courseName); LabelTextPanel courseInstructorInfo = new LabelTextPanel( new JLabel("Enter instructor name"), courseInstructor); LabelTextPanel taskNameInfo = new LabelTextPanel( new JLabel("Enter task title"), taskName); - LabelTextPanel taskIDInfo = new LabelTextPanel( - new JLabel("Enter task id"), taskID); + // 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 + + // buttons JButton cancel = new JButton("Cancel"); JButton save = new JButton("Save"); @@ -55,33 +58,38 @@ public CreateCourseScreen(CourseCreationController controller) { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + // create the new panel this.add(title); this.add(courseNameInfo); this.add(courseInstructorInfo); this.add(taskNameInfo); - this.add(taskIDInfo); this.add(buttons); } /** - * React to a button click ... + * React to a button click which triggers the corresponding use case */ + @Override public void actionPerformed(ActionEvent evt) { - System.out.println("Click " + evt.getActionCommand()); - - /** why no work :,( */ - try { - ArrayList task = new ArrayList(); - task.add("taskid"); - courseCreationController.create(courseName.getText(), - courseInstructor.getText(), task); // third argument should be taskName.getText() - JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); -// courseCreationController.create(courseName.getText(), -// courseInstructor.getText(), tasks.getText()); -// JOptionPane.showMessageDialog(this, String.format("%s created.".format(courseName.getText()))); - } catch (Exception e) { - JOptionPane.showMessageDialog(this, e.getMessage()); + // instructor decides to cancel the course creation process + if (evt.getActionCommand().equals("Cancel")) { + try { + // to do + JOptionPane.showMessageDialog(this, "screen should close"); + } catch (Exception e) { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + } else if (evt.getActionCommand().equals("Save")) { + try { + // initialize new Arraylist and add task + ArrayList tasks = new ArrayList(); + tasks.add(taskName.getText()); + courseCreationController.create(courseName.getText(), courseInstructor.getText(), + tasks); + JOptionPane.showMessageDialog(this, "Course successful created."); + } catch (Exception e) { + JOptionPane.showMessageDialog(this, e.getMessage()); + } } - } } diff --git a/src/main/java/screens/CourseEnrolmentScreen.java b/src/main/java/screens/CourseEnrolmentScreen.java index 3727167..176aafa 100644 --- a/src/main/java/screens/CourseEnrolmentScreen.java +++ b/src/main/java/screens/CourseEnrolmentScreen.java @@ -1,6 +1,6 @@ package screens; -// Framework / Drivers layer +// Framework/Drivers layer import javax.swing.*; import java.awt.*; From 7cb631824c6ddbe8a4bb6494633391fa480c6b7e Mon Sep 17 00:00:00 2001 From: jltng Date: Sun, 20 Nov 2022 21:08:07 -0500 Subject: [PATCH 19/22] course creation and course enrolment use cases core functionalities completed, and documentation added (minus data persistence and tests) --- .../CourseCreationDsGateway.java | 1 + .../CourseCreationInteractor.java | 13 ++-- .../CourseCreationPresenter.java | 2 +- .../CourseEnrolmentDsGateway.java | 4 +- .../CourseEnrolmentInputBoundary.java | 3 - .../CourseEnrolmentInteractor.java | 59 +++++++++++++------ .../CourseEnrolmentPresenter.java | 14 +++-- .../CourseEnrolmentRequestModel.java | 9 ++- .../CourseEnrolmentResponseModel.java | 13 ++-- src/main/java/entities/CourseMap.java | 3 +- 10 files changed, 74 insertions(+), 47 deletions(-) diff --git a/src/main/java/course_creation_use_case/CourseCreationDsGateway.java b/src/main/java/course_creation_use_case/CourseCreationDsGateway.java index e6003bb..7aa2e4e 100644 --- a/src/main/java/course_creation_use_case/CourseCreationDsGateway.java +++ b/src/main/java/course_creation_use_case/CourseCreationDsGateway.java @@ -8,6 +8,7 @@ */ public interface CourseCreationDsGateway { + // checks if the course is already in the course map by its unique id boolean existsByCourseID(String courseIdentifier); void saveCourse(CourseCreationRequestModel requestModel); diff --git a/src/main/java/course_creation_use_case/CourseCreationInteractor.java b/src/main/java/course_creation_use_case/CourseCreationInteractor.java index 5c09aae..34f37fb 100644 --- a/src/main/java/course_creation_use_case/CourseCreationInteractor.java +++ b/src/main/java/course_creation_use_case/CourseCreationInteractor.java @@ -18,7 +18,7 @@ public CourseCreationInteractor(CourseCreationDsGateway courseCreationDSGateway, /** * Creates the task in the request model and returns the corresponding response model - * @param requestModel the input from the return + * @param requestModel the input from the instructor */ @Override public CourseCreationResponseModel create(CourseCreationRequestModel requestModel) { @@ -27,13 +27,10 @@ public CourseCreationResponseModel create(CourseCreationRequestModel requestMode if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") || requestModel.getTasks().isEmpty()) { return courseCreationPresenter.prepareFailView("Please fill in all required information."); } - /* - Note: Jonathan - no need to check if is instructor; users would have different - views because they are in different use cases - If the course id (same course name and instructor name) already exists, new - course will not be made. - Else success - */ + + // Note: Jonathan - no need to check the type of User, students and instructors + // would have different views because they are in different use cases + // checks whether the course id is already in the CourseMap (course already exists) if (courseCreationDSGateway.existsByCourseID(requestModel.getCourseID())) { return courseCreationPresenter.prepareFailView("Course already exists."); } diff --git a/src/main/java/course_creation_use_case/CourseCreationPresenter.java b/src/main/java/course_creation_use_case/CourseCreationPresenter.java index 329d487..4f35bb8 100644 --- a/src/main/java/course_creation_use_case/CourseCreationPresenter.java +++ b/src/main/java/course_creation_use_case/CourseCreationPresenter.java @@ -11,7 +11,7 @@ public interface CourseCreationPresenter { CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel newCourse); /** - * Alerts user tht course creation attempted failed + * Alerts user that course creation attempted failed * @param error the output from the program */ CourseCreationResponseModel prepareFailView(String error); diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java index d35c274..b728cbe 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java @@ -3,9 +3,9 @@ // Use case layer public interface CourseEnrolmentDsGateway { - /* checks if student is in the course */ + // checks if student is in the course through the students argument of the Course + // object (value) from the course id (key) boolean existsByStudent(String studentIdentifier); -// void saveStudent(courseEnrolmentDsRequestModel requestModel); void saveStudent(CourseEnrolmentRequestModel requestModel); } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java index 1f38ba7..f99d3c8 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java @@ -2,9 +2,6 @@ // Use case layer -/* -* DONE -* */ public interface CourseEnrolmentInputBoundary { CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestModel); } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java index ce2a10f..718a23a 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java @@ -3,42 +3,63 @@ // Use case layer +import entities.*; + public class CourseEnrolmentInteractor implements CourseEnrolmentInputBoundary { final CourseEnrolmentDsGateway courseEnrolmentDsGateway; final CourseEnrolmentPresenter courseEnrolmentPresenter; + final CourseMap courseMap; + final String studentID; - public CourseEnrolmentInteractor(CourseEnrolmentDsGateway courseEnrolmentDsGateway, CourseEnrolmentPresenter courseEnrolmentPresenter) { + public CourseEnrolmentInteractor(CourseEnrolmentDsGateway courseEnrolmentDsGateway, CourseEnrolmentPresenter courseEnrolmentPresenter, + CourseMap courseMap, String studentID) { this.courseEnrolmentDsGateway = courseEnrolmentDsGateway; this.courseEnrolmentPresenter = courseEnrolmentPresenter; + this.courseMap = courseMap; + this.studentID = studentID; } + /** + * Executes task in the request model and returns the corresponding response model + * @param requestModel the input from the student user + */ @Override public CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestModel) { - /* At least one info box left blank */ - if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("")) { + + // At least one field left blank + if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") + || requestModel.getStudentID().equals("")) { return courseEnrolmentPresenter.prepareFailView("Please fill in all required information." ); - /* map is courseid --> Course - * checks if given course id is in the map of existing courses*/ } -// else if (!CourseMap.addCourse(requestModel.getCourseID())) { -// return courseEnrolmentPresenter.prepareFailView("Entered information does not correspond to an existing course."); -// } - /* - check whether student is enrolled in course - map is courseid --> Course objects - with valid courseid, go to Course.students and check if it contains STUDENT's id - */ + // checks if given course id is in the map of existing courses + if (CourseMap.findCourse(requestModel.getCourseID()) == null) { + return courseEnrolmentPresenter.prepareFailView("Entered information does not correspond to an existing course."); + } + + // checks whether the student is already enrolled in the course + // CourseMap is courseid : Course object + // with course id, find its corresponding Course value, go to its students parameter, and search through that :) + + // to do // if (CourseMap.value(requestModel.getCourseID()).contains(courseEnrolmentDsGateway.existsByStudent(requestModel.getStudentID()))) { // return courseEnrolmentPresenter.prepareFailView("Already enrolled in course."); // } - /* - add student id to courses' list of students - update + save coursemap edits - success view to presenter - */ + // checks passed; student id can be added to course's students parameter + + // get the student's id (their username) + String enrolledStudent = requestModel.getStudentID(); + // to do: add the student id to the associated courses' task parameter + // .getStudentId.add....... + + // course edits updated + // to do: need a 'updateCourse' method? - return null; + // sent to presenter + // to do: fix this + CourseEnrolmentResponseModel enrolmentResponseModel = + new CourseEnrolmentResponseModel(enrolledStudent.toLowerCase()); + return courseEnrolmentPresenter.prepareSuccessView(enrolmentResponseModel); } } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java index 6c771b7..dd06239 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java @@ -2,14 +2,18 @@ // Use case layer -/* -* Done? -* */ public interface CourseEnrolmentPresenter { - /* when course is found */ + + /** + * Alerts student user that course enrolment is successful + * @param newStudent output from the program (the student user that is enrolled in the course) + */ CourseEnrolmentResponseModel prepareSuccessView(CourseEnrolmentResponseModel newStudent); - /* when course name and instructor combo not present in database*/ + /** + * Alerts student user that course enrolment attempt failed + * @param error the output from the program + */ CourseEnrolmentResponseModel prepareFailView(String error); } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java index c394d09..523ac5a 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java @@ -6,11 +6,14 @@ public class CourseEnrolmentRequestModel { private String courseName; private String courseInstructor; private final String courseID; + private final String studentID; - public CourseEnrolmentRequestModel(String courseName, String courseInstructor) { + public CourseEnrolmentRequestModel(String courseName, String courseInstructor, + String studentID) { this.courseName = courseName; this.courseInstructor = courseInstructor; this.courseID = courseName + courseInstructor; + this.studentID = studentID; } /** @@ -35,4 +38,8 @@ public void setCourseInstructor() { String getCourseID() { return courseID; } + + String getStudentID() { + return studentID; + } } diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java index 923a23c..ac8dea6 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java @@ -4,25 +4,24 @@ public class CourseEnrolmentResponseModel { String studentID; - ArrayList tasks; // not sure if this goes here +// ArrayList tasks; // not sure if this goes here /** * The info that is stored in the database * The CourseMap will only be storing the IDs of enrolled StudentUsers * @param studentID the ID corresponding to the StudentUser - * @param tasks the tasks of the course */ - public CourseEnrolmentResponseModel(String studentID, ArrayList tasks) { + public CourseEnrolmentResponseModel(String studentID) { this.studentID = studentID; - this.tasks = tasks; +// this.tasks = tasks; } public String getStudentID() { return studentID; } - public ArrayList getTasks() { - return tasks; - } +// public ArrayList getTasks() { +// return tasks; +// } } diff --git a/src/main/java/entities/CourseMap.java b/src/main/java/entities/CourseMap.java index 4af1054..eae4450 100644 --- a/src/main/java/entities/CourseMap.java +++ b/src/main/java/entities/CourseMap.java @@ -10,12 +10,13 @@ public class CourseMap implements Serializable { private static HashMap 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 Course findCourse(String id) { + public static Course findCourse(String id) { return courseMap.get(id); } From 112e2edc6fef4085c5af4cae3689fcd043e5a7d3 Mon Sep 17 00:00:00 2001 From: jltng Date: Sun, 20 Nov 2022 21:27:08 -0500 Subject: [PATCH 20/22] fixed course enrolment screens and documentation added (minus data persistence and tests) --- .../java/screens/CourseCreationScreen.java | 7 ++-- .../screens/CourseEnrolmentController.java | 4 +-- .../java/screens/CourseEnrolmentFailed.java | 1 - .../CourseEnrolmentResponseFormatter.java | 12 ++++++- .../java/screens/CourseEnrolmentScreen.java | 36 ++++++++++++++----- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/main/java/screens/CourseCreationScreen.java b/src/main/java/screens/CourseCreationScreen.java index 168ebb6..14f6c7b 100644 --- a/src/main/java/screens/CourseCreationScreen.java +++ b/src/main/java/screens/CourseCreationScreen.java @@ -15,16 +15,15 @@ public class CourseCreationScreen extends JPanel implements ActionListener { /** the course instructor */ JTextField courseInstructor = new JTextField(15); - /* the part i don't understand ... tasks .... */ - /** title of task */ - JTextField taskName = new JTextField(25); + JTextField taskName = new JTextField(15); /** the controller */ CourseCreationController courseCreationController; /** - * A window with a title, texts to fill in, and JButtons */ + * A window with a title, texts to fill in, and JButtons + */ public CourseCreationScreen(CourseCreationController controller) { this.courseCreationController = controller; diff --git a/src/main/java/screens/CourseEnrolmentController.java b/src/main/java/screens/CourseEnrolmentController.java index 89b96ef..a1583cb 100644 --- a/src/main/java/screens/CourseEnrolmentController.java +++ b/src/main/java/screens/CourseEnrolmentController.java @@ -10,9 +10,9 @@ public CourseEnrolmentController(CourseEnrolmentInputBoundary enrolmentGateway) this.enrolmentInput = enrolmentGateway; } - CourseEnrolmentResponseModel create(String courseID, String instructorID) { + CourseEnrolmentResponseModel create(String courseID, String instructorID, String studentID) { CourseEnrolmentRequestModel requestModel = new CourseEnrolmentRequestModel( - courseID, instructorID); + courseID, instructorID, studentID); return enrolmentInput.create(requestModel); } diff --git a/src/main/java/screens/CourseEnrolmentFailed.java b/src/main/java/screens/CourseEnrolmentFailed.java index 9ee96b3..c42ca10 100644 --- a/src/main/java/screens/CourseEnrolmentFailed.java +++ b/src/main/java/screens/CourseEnrolmentFailed.java @@ -1,6 +1,5 @@ package screens; - public class CourseEnrolmentFailed extends RuntimeException { public CourseEnrolmentFailed(String error) { super(error); diff --git a/src/main/java/screens/CourseEnrolmentResponseFormatter.java b/src/main/java/screens/CourseEnrolmentResponseFormatter.java index ec0e1f6..a7fa05d 100644 --- a/src/main/java/screens/CourseEnrolmentResponseFormatter.java +++ b/src/main/java/screens/CourseEnrolmentResponseFormatter.java @@ -5,14 +5,24 @@ import course_enrolment_use_case.CourseEnrolmentPresenter; import course_enrolment_use_case.CourseEnrolmentResponseModel; +import javax.swing.*; + public class CourseEnrolmentResponseFormatter implements CourseEnrolmentPresenter { + /** + * Alert student user about course enrolment success + * @param response output from the program (the student user that is enrolled in the course) + */ @Override public CourseEnrolmentResponseModel prepareSuccessView(CourseEnrolmentResponseModel response) { - /* what is this */ + JOptionPane.showMessageDialog(null, "Successfully enrolled!"); return response; } + /** + * Alert student user about course enrolment failure + * @param error the output from the program + */ @Override public CourseEnrolmentResponseModel prepareFailView(String error) { throw new CourseEnrolmentFailed(error); diff --git a/src/main/java/screens/CourseEnrolmentScreen.java b/src/main/java/screens/CourseEnrolmentScreen.java index 176aafa..5c3dc59 100644 --- a/src/main/java/screens/CourseEnrolmentScreen.java +++ b/src/main/java/screens/CourseEnrolmentScreen.java @@ -14,23 +14,31 @@ public class CourseEnrolmentScreen extends JPanel implements ActionListener { /** student enters course instructor */ JTextField courseInstructor = new JTextField(15); + /** student enters their username (aka student id) */ + JTextField studentID = new JTextField(15); + /** the controller */ CourseEnrolmentController courseEnrolmentController; /** - * Window with title and JButtons + * Window with title, texts to fill in, and JButtons */ public CourseEnrolmentScreen(CourseEnrolmentController controller) { this.courseEnrolmentController = controller; + // label for the title of the screen JLabel title = new JLabel("Course Enrolment Screen"); title.setAlignmentX(Component.CENTER_ALIGNMENT); + // text fields for student user to enter in required info LabelTextPanel courseNameInfo = new LabelTextPanel( new JLabel("Enter course name"), courseName); LabelTextPanel courseInstructorInfo = new LabelTextPanel( new JLabel("Enter instructor name"), courseInstructor); + LabelTextPanel studentIDInfo = new LabelTextPanel( + new JLabel("Enter instructor name"), studentID); + // buttons JButton cancel = new JButton("Cancel"); JButton search = new JButton("Search"); @@ -43,22 +51,34 @@ public CourseEnrolmentScreen(CourseEnrolmentController controller) { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + // create the new panel this.add(title); this.add(courseNameInfo); this.add(courseInstructorInfo); + this.add(studentIDInfo); this.add(buttons); } /** - * reacting to button clicks? + * React to a button click which triggers the corresponding use case */ + @Override public void actionPerformed(ActionEvent evt) { - System.out.println("Click " + evt.getActionCommand()); - - try { -// courseEnrolmentController.cre - } catch (Exception e) { - JOptionPane.showMessageDialog(this, e.getMessage()); + // student user decides to cancel course enrolment process + if (evt.getActionCommand().equals("Cancel")) { + try { + // do to + JOptionPane.showMessageDialog(this, "screen should close"); + } catch (Exception e) { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + } else if (evt.getActionCommand().equals("Search")) { + try { + // to do: add studentID to course's task parameter + JOptionPane.showMessageDialog(this, "Successfully enrolled in course."); + } catch (Exception e) { + JOptionPane.showMessageDialog(this, e.getMessage()); + } } } } From 91c28629e758e1abf3cd0c4a2ef4ac59d20a4a01 Mon Sep 17 00:00:00 2001 From: jltng Date: Mon, 21 Nov 2022 00:12:39 -0500 Subject: [PATCH 21/22] added student id getter for course enrolment request model --- .../CourseEnrolmentRequestModel.java | 8 ++++---- .../TaskToTasklistInteractor.java | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java b/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java index 523ac5a..1eeae6d 100644 --- a/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java +++ b/src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java @@ -19,7 +19,7 @@ public CourseEnrolmentRequestModel(String courseName, String courseInstructor, /** * Change getters to public? */ - String getCourseName() { + public String getCourseName() { return courseName; } @@ -27,7 +27,7 @@ public void setCourseName() { this.courseName = courseName; } - String getCourseInstructor() { + public String getCourseInstructor() { return courseInstructor; } @@ -35,11 +35,11 @@ public void setCourseInstructor() { this.courseInstructor = courseInstructor; } - String getCourseID() { + public String getCourseID() { return courseID; } - String getStudentID() { + public String getStudentID() { return studentID; } } diff --git a/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java b/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java index 5aa7832..de154a0 100644 --- a/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java +++ b/src/main/java/tasks_to_student_tasklist_use_case/TaskToTasklistInteractor.java @@ -1,4 +1,6 @@ package tasks_to_student_tasklist_use_case; public class TaskToTasklistInteractor { + // request model is the student's id and the course id + // i can do this in the course enrolment use case ..... } From df33dec63ad1b5d42e01b2e213c58e56d2c297ab Mon Sep 17 00:00:00 2001 From: jltng Date: Mon, 21 Nov 2022 13:04:19 -0500 Subject: [PATCH 22/22] added student id getter for course enrolment request model --- test/{entities => }/CourseUnitTest.java | 2 -- 1 file changed, 2 deletions(-) rename test/{entities => }/CourseUnitTest.java (95%) diff --git a/test/entities/CourseUnitTest.java b/test/CourseUnitTest.java similarity index 95% rename from test/entities/CourseUnitTest.java rename to test/CourseUnitTest.java index bbcbc7f..357cdf1 100644 --- a/test/entities/CourseUnitTest.java +++ b/test/CourseUnitTest.java @@ -1,5 +1,3 @@ -package entities; - //import org.junit.jupiter.api.Test; // //import static org.junit.jupiter.api.Assertions.assertFalse;