Skip to content
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
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
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 Nov 14, 2022
5c5398a
test commit - need to move around files and rename packages for each …
jltng Nov 16, 2022
d4be5cf
added CourseMap entity, started unit tests, fixed use case files
jltng Nov 16, 2022
47ea703
use case layer for course enrolment use case completed with except in…
jltng Nov 17, 2022
2ccf7a4
use case layer for course enrolment use case completed with except in…
jltng Nov 17, 2022
f197494
Merge pull request #24 from CSC207-2022F-UofT/main
jltng Nov 17, 2022
8b5d1c8
deleted useCase files
jltng Nov 17, 2022
9bfa7a7
entity layer - added course factory // screen layer = started screens…
jltng Nov 18, 2022
89d11ee
course creation screen loads, not yet responsive
jltng Nov 18, 2022
c7ebd96
changed course creation use case files to not include ds request mode…
jltng Nov 18, 2022
f95d522
started screens for course enrolment use case
jltng Nov 18, 2022
c71b774
renamed entity layer files to java naming convention, added course fo…
jltng Nov 19, 2022
af6175c
fixed course creation interactor
jltng Nov 19, 2022
e0e2f72
deleted unnecessary files
jltng Nov 19, 2022
f92b2ce
deleted unnecessary file
jltng Nov 19, 2022
2f2d84e
empty use case 3 (task to task list) files
jltng Nov 19, 2022
7bdb531
minor changes to main
jltng Nov 19, 2022
87e06fa
removed main file so that it wouldn't push to pr branch
jltng Nov 19, 2022
d8acd6b
Merge remote-tracking branch 'origin/Feature-7-Core-Functionalities' …
jltng Nov 19, 2022
703bf4b
renamed entities package to proper java naming convention, commented …
jltng Nov 19, 2022
da810e9
course creation use case completed and documentation added (minus dat…
jltng Nov 21, 2022
7cb6318
course creation and course enrolment use cases core functionalities c…
jltng Nov 21, 2022
112e2ed
fixed course enrolment screens and documentation added (minus data pe…
jltng Nov 21, 2022
91c2862
added student id getter for course enrolment request model
jltng Nov 21, 2022
df33dec
added student id getter for course enrolment request model
jltng Nov 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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);
}
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);
}
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);
}
}
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);
}
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;
}
}
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;
}
}

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);
}
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);
}
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);
}
}
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);
}
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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes?

*/
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;
}
}
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;
// }
}
Loading