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 - Tests and README #84

Merged
merged 20 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

Start up the program by running the `Main.java` class in the `src/main/java` directory.
Upon launching the program, a welcome screen with two buttons, `Sign Up` and `Log In`, appears.
**Note**: For the course enrolment use case, upon having a `InstructorUser` create a `Course`, the program would need to be closed and rerun so that the data files update accordingly.

![](resources/images/welcome_screen.png)

Expand Down Expand Up @@ -141,18 +142,21 @@ For at least one of these tasks, the student specifies the "target task(s)" and
If more than one target task is specified and the target grades in the input differ, the output will be calculated using the right-most target grade.


## Course Enrolment/Creation
## Course Creation/Enrolment

If the user clicks on the `Courses` button, the screen for course enrolment (`StudentUser` only) and course creation (`InstructorUser` only) will be displayed.
On this screen, the user can either enrol in a course or create a course, depending on their type.

**Course creation:**
Upon clicking the `Create a Course` button, the instructor will be prompted to enter in the following text fields: the course name, the course instructor, and a task _(in future implementation they would be able to add more than one task)_.

![](resources/images/course_creation_screen.png)
![](resources/images/course_creation_empty_screen.png)

If the instructor clicks the `Create` button, the program will check whether the course already exists in the CourseMap and if all required fields are filled out.
If any of checks failed, an error message will pop up.

![](resources/images/creation_exists_msg.png)

Once successful, the `Course` will be added to the `CourseMap`, where its key is the course ID, a unique string made up of the concatenation of the course name and course instructor entered by the instructor themselves.
After the program has completed the course creation, the success message will pop up.
During the entire creation process, clicking the `Cancel` button will close the window without any searches performed.
Expand All @@ -164,4 +168,9 @@ If any of the checks failed, an error message would pop up.
Once successful, the username of the students (which is their unique ID) will be added to the `students` parameter (which is an ArrayList of strings) of the `Course` entity associated with the course ID.
Then, the tasks (ArrayList of strings from the `tasks` parameter in the `Course` entity) will be copied and appended to the student’s own task list.
After the program has completed the course enrolment, the success message will pop up.
During the entire enrolment process, clicking the `Cancel` button will close the window without any searches performed.

![](resources/images/course_enrolment_sucess.png)

![](resources/images/enrolment_success_message.png)

During the entire enrolment process, clicking the `Cancel` button will close the window without any searches performed.
Binary file added resources/images/course_creation_empty_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/course_enrolment_sucess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/creation_exists_msg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/enrolment_success_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio

// Adding in course enrolment use case
CourseEnrolmentCourseDsGateway enrolCourse = new FileCourse("src/main/java/data/courses.ser");
CourseEnrolmentUserDsGateway enrolUser = new FileUser("src/main/java/data/users.ser");
CourseEnrolmentTaskDsGateway enrolTasks = new FileTaskMap("src/main/java/data/TaskMap.txt");
CourseEnrolmentOutputBoundary enrolmentPresenter = new CourseEnrolmentPresenter();
CourseEnrolmentInputBoundary enrolmentInteractor = new CourseEnrolmentInteractor(
enrolUser, enrolCourse, enrolTasks, enrolmentPresenter);
enrolCourse, enrolTasks, enrolmentPresenter);
CourseEnrolmentController enrolmentController = new CourseEnrolmentController(enrolmentInteractor);

// Adding in logout use case
Expand Down
Empty file removed src/main/java/data/users
Empty file.
8 changes: 8 additions & 0 deletions src/main/java/entities/Assignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,12 @@ public void setPrepTimeScheduled(ArrayList<ArrayList<LocalDateTime>> prepTimeSch
public LocalDateTime getDueDate() {
return this.dueDate;
}

/**
* For course enrolment use case
* @return a copy of the assignment
*/
public Assignment getAssignmentCopy() {
return new Assignment(getTitle(), "", dueDate, weightage);
}
}
2 changes: 1 addition & 1 deletion src/main/java/entities/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getCourseID() {
}

public ArrayList<String> getStudents() {
return new ArrayList<>(this.students);
return students;
}

public ArrayList<String> getTasks() {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/entities/TaskMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class TaskMap implements Serializable {
private static HashMap<String, Task> taskMap;
Expand All @@ -26,6 +27,11 @@ public static void addTask(String id, Task task) {
taskMap.put(id, task);
}

public static void addTasks(Map newTasks) {
taskMap.putAll(newTasks);

}

/**
* Remove a Task from the TaskMap.txt
* @param id - the ID of the Task being removed
Expand All @@ -49,5 +55,4 @@ public static HashMap<String, Task> getTaskMap() {
public static void setTaskMap(HashMap<String, Task> tasksMap) {
taskMap = tasksMap;
}

}
4 changes: 4 additions & 0 deletions src/main/java/entities/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,8 @@ public ArrayList<ArrayList<LocalDateTime>> getPrepTimeScheduled() {
public void setPrepTimeScheduled(ArrayList<ArrayList<LocalDateTime>> prepTimeScheduled) {
this.prepTimeScheduled = prepTimeScheduled;
}

public Test getTestCopy() {
return new Test(getTitle(), "", startTime, endTime, weightage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public CourseEnrolmentController(CourseEnrolmentInputBoundary enrolmentGateway)
this.enrolmentInput = enrolmentGateway;
}

void enrol(String courseID, String instructorID, String studentID) {
void enrol(String courseID, String instructorID) {
CourseEnrolmentRequestModel requestModel = new CourseEnrolmentRequestModel(
courseID, instructorID, studentID);
courseID, instructorID);

enrolmentInput.enrol(requestModel);
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/screens/course_features/CourseEnrolmentScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public CourseEnrolmentScreen(CourseEnrolmentController controller, JPanel screen
new JLabel("Enter course name"), courseName);
LabelTextPanel courseInstructorInfo = new LabelTextPanel(
new JLabel("Enter instructor name"), courseInstructor);
LabelTextPanel studentIDInfo = new LabelTextPanel(
new JLabel("Enter your username"), studentID);
// LabelTextPanel studentIDInfo = new LabelTextPanel(
// new JLabel("Enter your username"), studentID);

// buttons
JButton cancel = new JButton("Cancel");
Expand All @@ -65,7 +65,6 @@ public CourseEnrolmentScreen(CourseEnrolmentController controller, JPanel screen
this.add(title);
this.add(courseNameInfo);
this.add(courseInstructorInfo);
this.add(studentIDInfo);
this.add(buttons);
}

Expand All @@ -84,8 +83,10 @@ public void actionPerformed(ActionEvent evt) {
// add course tasks to Student's todolist
// add course id to Student's courses list

courseEnrolmentController.enrol(courseName.getText(), courseInstructor.getText(), studentID.getText());
JOptionPane.showMessageDialog(this, "Successfully enrolled in course. tasks added.");
courseEnrolmentController.enrol(courseName.getText(), courseInstructor.getText());
JOptionPane.showMessageDialog(this,
"Successfully enrolled in course " + courseName.getText() + " with instructor" +
courseInstructor.getText() + ". Check your to-do list for the course tasks!");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Expand Down
40 changes: 1 addition & 39 deletions src/main/java/screens/login_registration/FileUser.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package screens.login_registration;

import use_cases.course_features.course_enrolment_use_case.*;
import use_cases.login_registration.login_usecase.*;
import use_cases.login_registration.logout_usecase.*;
import use_cases.login_registration.user_register_usecase.*;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway, CourseEnrolmentUserDsGateway {
public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway {

private static HashMap<String, UserRegSaveRequest> accounts;

Expand Down Expand Up @@ -94,40 +92,4 @@ public String passOf(String name) {
public Map<String, UserRegSaveRequest> getAccounts() {
return accounts;
}


/**
* For course enrolment use case (course tasks to do list gateway)
* Adds the course tasks to the student's to-do list
*
* @param studentID the username of the student whose parameters are being modified
* @param courseTasks the course task ids what will be added to the student's 'to do list' parameter
*/
@Override
public void addTasksToTodolist(String studentID, ArrayList<String> courseTasks) throws IOException {
// casting to student save request
((StudentSaveRequest) accounts.get(studentID)).getToDoList().addAll(courseTasks);
save();
// in interactor, update CurrentUser
// make a new StudentSaveRequest with CurrentUser
// call Gateway.save(StudentSaveRequest)
}

/**
* For course enrolment use case (course tasks to do list gateway)
* Adds the course id to the student's 'courses' parameter
* @param courseID the course the student enrolled in
* @param studentID the username of student enrolled
*/
@Override
public void addCourseToStudent(String courseID, String studentID) throws IOException {
// casting to student save request
// initialize current
// StudentUser s = accounts.get(studentID);
((StudentSaveRequest) accounts.get(studentID)).getCourses().add(courseID);
save();
// if adding
// StudentUser s = (StudentUser) CurrentUser.getCurrentUser()
// s.addCourse
}
}
17 changes: 15 additions & 2 deletions src/main/java/screens/task_management/FileTaskMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class FileTaskMap implements TaskMapGateway, CourseEnrolmentTaskDsGateway, ScheduleCTDSGateway {
String path;
Expand Down Expand Up @@ -69,15 +70,27 @@ public boolean existsById(String id) {
* @param taskId the unique id (key) of the task
* @return task
*/

/**
* For course enrolment use case, get a Task based on task id
* @param taskId - the uniqueid of the task
*/
@Override
public Task getTask(String taskId) {
return taskMap.get(taskId);
}

/**
* For course enrolment use case, added temporary map of new tasks to TaskMap
* @param newMap the temporary map of 'cloned' course tasks with student username in id
*/
@Override
public void saveNewMaptoMap(HashMap<String, Task> newMap) {
taskMap.putAll(newMap);
save(taskMap);
for (Map.Entry<String, Task> entry: newMap.entrySet()) {
taskMap.put(entry.getKey(), entry.getValue());
save(taskMap);
}
TaskMap.setTaskMap(taskMap);
}

/**
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/screens/task_management/InMemoryTaskMap.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package screens.task_management;

import entities.*;
import use_cases.course_features.course_enrolment_use_case.*;
import use_cases.task_management.read_write.*;

import java.util.HashMap;
import java.util.Map;

/**
* TaskMapGateway for testing purposes
*/
public class InMemoryTaskMap implements TaskMapGateway {
public class InMemoryTaskMap implements TaskMapGateway, CourseEnrolmentTaskDsGateway {
HashMap<String, Task> taskMap = new HashMap<>();

/**
Expand Down Expand Up @@ -37,4 +39,26 @@ public Object load() {
public boolean existsById(String id) {
return taskMap.containsKey(id);
}

/**
* course enrolment use case (for interactor test)
* @param taskID the unique id of the task
*/
@Override
public Task getTask(String taskID) {
return taskMap.get(taskID);
}

/**
* course enrolment use case (for interactor test)
* @param newMap the map of the "new" tasks (new key, same value)
*/
@Override
public void saveNewMaptoMap(HashMap<String, Task> newMap) {
for (Map.Entry<String, Task> entry : newMap.entrySet()) {
taskMap.put(entry.getKey(), entry.getValue());
save(taskMap);
}
TaskMap.setTaskMap(taskMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void actionPerformed(ActionEvent evt) {

// notify user of success and return to main screen
showMessageDialog(this, "Assignment Created Successfully");
screenLayout.show(screens, "StudentMain");
screenLayout.show(screens, "InstructorMain");
} catch (Exception e) { // if anything goes wrong in the input (e.g. parsing error)
showMessageDialog(this, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ public String getCourseID() {
}

public ArrayList<String> getTasks() {
// string from input will be like this: "task1,task2,task3"
// need to split into ["task1", "task2", "task3"]

String taskOneString = tasks.get(0); // only one element in arraylist
ArrayList<String> courseTasksSplit = new ArrayList<>();
Collections.addAll(courseTasksSplit, taskOneString.split(","));
return courseTasksSplit;
return tasks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface CourseEnrolmentCourseDsGateway {
boolean existsByCourseID(String courseIdentifier); // exact same name as CourseCreationDsGateway
Course searchForCourse(String courseIdentifier);
boolean existsStudentInCourse(String courseID, String studentIdentifier);
void saveStudentToCourse(String studentID, String courseID) throws IOException; // need to update data
void saveStudentToCourse(String studentID, String courseID) throws IOException;
ArrayList<String> getCourseTasks(String courseIdentifier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

// Use case layer

/**
* Input boundary interface
* Dependency inversion from controller to interactor
*/
public interface CourseEnrolmentInputBoundary {
/**
* the method in the use case interactor that does the entire enrolment process
* @param requestModel the request model (information inputted by user)
*/
void enrol(CourseEnrolmentRequestModel requestModel);
}
Loading