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); +// } +//}