Skip to content

Commit

Permalink
added CourseMap entity, started unit tests, fixed use case files
Browse files Browse the repository at this point in the history
  • Loading branch information
jltng committed Nov 16, 2022
1 parent 5c5398a commit d4be5cf
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 49 deletions.
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
42 changes: 42 additions & 0 deletions src/main/java/Entities/CourseMap.java
Original file line number Diff line number Diff line change
@@ -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<String, Course> 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() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
public class courseCreationDSRequestModel {
private final String courseName;
private final String courseInstructor;
private final String courseID;
private ArrayList<String> tasks;

public courseCreationDSRequestModel(String courseName, String courseInstructor, ArrayList<String> tasks) {
this.courseName = courseName;
this.courseInstructor = courseInstructor;
this.courseID = courseName + courseInstructor;
this.tasks = tasks;
}

Expand All @@ -25,6 +27,9 @@ public String getCourseName() {
public String getCourseInstructor() {
return courseInstructor;
}
public String getCourseID() {
return courseID;
}
public ArrayList<String> getTasks() {
return tasks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -43,6 +45,7 @@ String getCourseID() {
}

public ArrayList<String> getTasks() {

return tasks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> tasks;

public courseCreationResponseModel(String courseName, String instructorName) {
this.courseName = courseName;
this.instructorName = instructorName;
}

public String getCourseName() {
return this.courseName;
public courseCreationResponseModel(String courseID, ArrayList<String> 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<String> 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<String> getTasks() {
// return this.tasks;
// }
//
// public void setTasks() {
// this.tasks = tasks;
// }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package course_creation_use_case;

public class CourseCreationInteractorTest {
}
15 changes: 15 additions & 0 deletions test/entities/CourseUnitTest.java
Original file line number Diff line number Diff line change
@@ -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);
// }
//}

0 comments on commit d4be5cf

Please sign in to comment.