-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature 7 course creation + course enrolment + tasks to tasklist use cases #34
Closed
Closed
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7a44a64
course creation skeleton files
jltng 5c5398a
test commit - need to move around files and rename packages for each …
jltng d4be5cf
added CourseMap entity, started unit tests, fixed use case files
jltng 47ea703
use case layer for course enrolment use case completed with except in…
jltng 2ccf7a4
use case layer for course enrolment use case completed with except in…
jltng f197494
Merge pull request #24 from CSC207-2022F-UofT/main
jltng 8b5d1c8
deleted useCase files
jltng 9bfa7a7
entity layer - added course factory // screen layer = started screens…
jltng 89d11ee
course creation screen loads, not yet responsive
jltng c7ebd96
changed course creation use case files to not include ds request mode…
jltng f95d522
started screens for course enrolment use case
jltng c71b774
renamed entity layer files to java naming convention, added course fo…
jltng af6175c
fixed course creation interactor
jltng e0e2f72
deleted unnecessary files
jltng f92b2ce
deleted unnecessary file
jltng 2f2d84e
empty use case 3 (task to task list) files
jltng 7bdb531
minor changes to main
jltng 87e06fa
removed main file so that it wouldn't push to pr branch
jltng d8acd6b
Merge remote-tracking branch 'origin/Feature-7-Core-Functionalities' …
jltng 703bf4b
renamed entities package to proper java naming convention, commented …
jltng da810e9
course creation use case completed and documentation added (minus dat…
jltng 7cb6318
course creation and course enrolment use cases core functionalities c…
jltng 112e2ed
fixed course enrolment screens and documentation added (minus data pe…
jltng 91c2862
added student id getter for course enrolment request model
jltng df33dec
added student id getter for course enrolment request model
jltng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/course_creation_use_case/CourseCreationDsGateway.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package course_creation_use_case; | ||
|
||
// Use case layer | ||
|
||
/* | ||
Notes: | ||
- the methods the repo needs to implement for the interactor to do its job | ||
*/ | ||
|
||
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); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/course_creation_use_case/CourseCreationInputBoundary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package course_creation_use_case; | ||
|
||
// Use case layer | ||
|
||
|
||
/* | ||
Notes: | ||
- 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); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/course_creation_use_case/CourseCreationInteractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package course_creation_use_case; | ||
|
||
// Use case layer | ||
|
||
import entities.*; | ||
|
||
public class CourseCreationInteractor implements CourseCreationInputBoundary { | ||
final CourseCreationDsGateway courseCreationDSGateway; | ||
final CourseCreationPresenter courseCreationPresenter; | ||
final CourseMap courseMap; | ||
|
||
public CourseCreationInteractor(CourseCreationDsGateway courseCreationDSGateway, CourseCreationPresenter courseCreationPresenter, | ||
CourseMap courseMap) { | ||
this.courseCreationDSGateway = courseCreationDSGateway; | ||
this.courseCreationPresenter = courseCreationPresenter; | ||
this.courseMap = courseMap; | ||
} | ||
|
||
/** | ||
* Creates the task in the request model and returns the corresponding response model | ||
* @param requestModel the input from the instructor | ||
*/ | ||
@Override | ||
public CourseCreationResponseModel create(CourseCreationRequestModel requestModel) { | ||
|
||
// 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."); | ||
} | ||
|
||
// 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."); | ||
} | ||
|
||
// 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); | ||
|
||
// course successfully created and saved | ||
CourseCreationRequestModel courseCreationModel = new CourseCreationRequestModel(course.getCourseName(), course.getCourseInstructor(), course.getTasks()); | ||
courseCreationDSGateway.saveCourse(courseCreationModel); | ||
|
||
// course sent to presenter | ||
CourseCreationResponseModel courseResponseModel = new CourseCreationResponseModel( | ||
course.getCourseID(), course.getTasks()); | ||
return courseCreationPresenter.prepareSuccessView(courseResponseModel); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/course_creation_use_case/CourseCreationPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package course_creation_use_case; | ||
|
||
// Use case layer | ||
|
||
public interface CourseCreationPresenter { | ||
|
||
/** | ||
* Alerts user that course creation is successful (no existing course) | ||
* @param newCourse the output from the program | ||
*/ | ||
CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel newCourse); | ||
|
||
/** | ||
* Alerts user that course creation attempted failed | ||
* @param error the output from the program | ||
*/ | ||
CourseCreationResponseModel prepareFailView(String error); | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/course_creation_use_case/CourseCreationRequestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package course_creation_use_case; | ||
|
||
// Use case layer | ||
|
||
/* | ||
Notes: | ||
- 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; | ||
|
||
public class CourseCreationRequestModel { | ||
private String courseName; | ||
private String courseInstructor; | ||
private final String courseID; | ||
private ArrayList<String> 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<String> tasks) { | ||
this.courseName = courseName; | ||
this.courseInstructor = courseInstructor; | ||
this.courseID = courseName + courseInstructor; | ||
this.tasks = tasks; | ||
} | ||
|
||
public String getCourseName() { | ||
return courseName; | ||
} | ||
|
||
public void setCourseName() { | ||
|
||
this.courseName = courseName; | ||
} | ||
|
||
public String getCourseInstructor() { | ||
return courseInstructor; | ||
} | ||
|
||
public void setCourseInstructor() { | ||
|
||
this.courseInstructor = courseInstructor; | ||
} | ||
|
||
public String getCourseID() { | ||
return courseID; | ||
} | ||
|
||
public ArrayList<String> getTasks() { | ||
|
||
return tasks; | ||
} | ||
|
||
public void setTasks() { | ||
this.tasks = tasks; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/course_creation_use_case/CourseCreationResponseModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package course_creation_use_case; | ||
|
||
import java.util.ArrayList; | ||
|
||
// Use case layer | ||
|
||
/* | ||
Notes: | ||
- the output data produced; returns the response as the output | ||
- does NOT depend on anything NOR should have any references to Entity objects: violates SRP | ||
*/ | ||
|
||
public class CourseCreationResponseModel { | ||
String courseID; | ||
ArrayList<String> 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<String> tasks) { | ||
this.courseID = courseID; | ||
this.tasks = tasks; | ||
} | ||
public String getCourseID() { | ||
return courseID; | ||
} | ||
public void setCourseID() { | ||
this.courseID = courseID; | ||
} | ||
public ArrayList<String> getTasks() { | ||
return tasks; | ||
} | ||
|
||
// i don't think this is needed | ||
public void setTasks() { | ||
this.tasks = tasks; | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
src/main/java/course_enrolment_use_case/CourseEnrolmentDsGateway.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package course_enrolment_use_case; | ||
|
||
// Use case layer | ||
|
||
public interface CourseEnrolmentDsGateway { | ||
// 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(CourseEnrolmentRequestModel requestModel); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/course_enrolment_use_case/CourseEnrolmentInputBoundary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package course_enrolment_use_case; | ||
|
||
// Use case layer | ||
|
||
public interface CourseEnrolmentInputBoundary { | ||
CourseEnrolmentResponseModel create(CourseEnrolmentRequestModel requestModel); | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/course_enrolment_use_case/CourseEnrolmentInteractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package course_enrolment_use_case; | ||
|
||
|
||
// 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, | ||
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 field left blank | ||
if (requestModel.getCourseName().equals("") || requestModel.getCourseInstructor().equals("") | ||
|| requestModel.getStudentID().equals("")) { | ||
return courseEnrolmentPresenter.prepareFailView("Please fill in all required information." ); | ||
} | ||
|
||
// 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."); | ||
// } | ||
|
||
// 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? | ||
|
||
// sent to presenter | ||
// to do: fix this | ||
CourseEnrolmentResponseModel enrolmentResponseModel = | ||
new CourseEnrolmentResponseModel(enrolledStudent.toLowerCase()); | ||
return courseEnrolmentPresenter.prepareSuccessView(enrolmentResponseModel); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/course_enrolment_use_case/CourseEnrolmentPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package course_enrolment_use_case; | ||
|
||
// Use case layer | ||
|
||
|
||
public interface CourseEnrolmentPresenter { | ||
|
||
/** | ||
* 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); | ||
|
||
/** | ||
* Alerts student user that course enrolment attempt failed | ||
* @param error the output from the program | ||
*/ | ||
CourseEnrolmentResponseModel prepareFailView(String error); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/course_enrolment_use_case/CourseEnrolmentRequestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package course_enrolment_use_case; | ||
|
||
// Use case layer | ||
|
||
public class CourseEnrolmentRequestModel { | ||
private String courseName; | ||
private String courseInstructor; | ||
private final String courseID; | ||
private final String studentID; | ||
|
||
public CourseEnrolmentRequestModel(String courseName, String courseInstructor, | ||
String studentID) { | ||
this.courseName = courseName; | ||
this.courseInstructor = courseInstructor; | ||
this.courseID = courseName + courseInstructor; | ||
this.studentID = studentID; | ||
} | ||
|
||
/** | ||
* Change getters to public? | ||
*/ | ||
public String getCourseName() { | ||
return courseName; | ||
} | ||
|
||
public void setCourseName() { | ||
this.courseName = courseName; | ||
} | ||
|
||
public String getCourseInstructor() { | ||
return courseInstructor; | ||
} | ||
|
||
public void setCourseInstructor() { | ||
this.courseInstructor = courseInstructor; | ||
} | ||
|
||
public String getCourseID() { | ||
return courseID; | ||
} | ||
|
||
public String getStudentID() { | ||
return studentID; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/course_enrolment_use_case/CourseEnrolmentResponseModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package course_enrolment_use_case; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class CourseEnrolmentResponseModel { | ||
String studentID; | ||
// ArrayList<String> 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 | ||
*/ | ||
public CourseEnrolmentResponseModel(String studentID) { | ||
this.studentID = studentID; | ||
// this.tasks = tasks; | ||
} | ||
|
||
public String getStudentID() { | ||
return studentID; | ||
} | ||
|
||
// public ArrayList<String> getTasks() { | ||
// return tasks; | ||
// } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes?