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

Correct format 1 #41

Closed
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
Binary file added IndividualProject/data.txt
Binary file not shown.
9 changes: 7 additions & 2 deletions IndividualProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -80,8 +85,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package dev.coms4156.project.individualproject;

import java.io.*;

import java.io.Serial;
import java.io.Serializable;

/**
* Represents a course within an educational institution.
* This class stores information about the course, including its location,
* instructor name, time slot, and enrollment capacity.
*/
public class Course implements Serializable {

/**
Expand All @@ -20,17 +26,17 @@ public Course(String instructorName, String courseLocation, String timeSlot, int
this.enrolledStudentCount = 500;
}

/**
/**
* Enrolls a student in the course if there is space available.
*
* @return true if the student is successfully enrolled, false otherwise.
*/
public boolean enrollStudent() {
enrolledStudentCount++;
enrolledStudentCount++;
return false;
}

/**
/**
* Drops a student from the course if a student is enrolled.
*
* @return true if the student is successfully dropped, false otherwise.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dev.coms4156.project.individualproject;

import java.io.*;
import java.util.*;

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

/**
* Represents a department within an educational institution.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.coms4156.project.individualproject;

import jakarta.annotation.PreDestroy;
import java.util.*;
import org.springframework.boot.*;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.HashMap;

/**
* Class contains all the startup logic for the application.
*
Expand Down Expand Up @@ -34,34 +36,34 @@ public static void main(String[] args) {
* @param args A {@code String[]} of any potential runtime args
*/
public void run(String[] args) {
for (String arg : args) {
if (arg.equals("setup")) {
myFileDatabase = new MyFileDatabase(1, "./data.txt");
resetDataFile();
System.out.println("System Setup");
return;
}
for (String arg : args) {
if (arg.equals("setup")) {
myFileDatabase = new MyFileDatabase(1, "./data.txt");
resetDataFile();
System.out.println("System Setup");
return;
}
}
myFileDatabase = new MyFileDatabase(0, "./data.txt");
System.out.println("Start up");
}

/**
* Overrides the database reference, used when testing.
*
* @param testData A {@code MyFileDatabase} object referencing test data.
*/
public static void overrideDatabase(MyFileDatabase testData) {
myFileDatabase = testData;
saveData = false;
}
*
* @param testData A {@code MyFileDatabase} object referencing test data.
*/
public static void overrideDatabase(MyFileDatabase testData) {
myFileDatabase = testData;
saveData = false;
}

/**
* Allows for data to be reset in event of errors.
*/
public void resetDataFile() {
String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"};
String[] locations = {"417 IAB", "309 HAV", "301 URIS"};
/**
* Allows for data to be reset in event of errors.
*/
public void resetDataFile() {
String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"};
String[] locations = {"417 IAB", "309 HAV", "301 URIS"};

//data for coms dept
Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400);
Expand Down Expand Up @@ -129,20 +131,20 @@ public void resetDataFile() {
ieor2500.setEnrolledStudentCount(52);
Course ieor3404 = new Course("Christopher J Dolan", "303 MUDD", times[2], 73);
ieor3404.setEnrolledStudentCount(80);
Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96);
ieor3658.setEnrolledStudentCount(87);
Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110);
ieor4102.setEnrolledStudentCount(92);
Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150);
ieor4106.setEnrolledStudentCount(161);
Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96);
ieor3658.setEnrolledStudentCount(87);
Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110);
ieor4102.setEnrolledStudentCount(92);
Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150);
ieor4106.setEnrolledStudentCount(161);
Course ieor4405 = new Course("Yuri Faenza", "517 HAV", times[0], 80);
ieor4405.setEnrolledStudentCount(19);
Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150);
ieor4511.setEnrolledStudentCount(50);
Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60);
ieor4540.setEnrolledStudentCount(33);
ieor4405.setEnrolledStudentCount(19);
Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150);
ieor4511.setEnrolledStudentCount(50);
Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60);
ieor4540.setEnrolledStudentCount(33);

courses = new HashMap<>();
courses = new HashMap<>();
courses.put("2500", ieor2500);
courses.put("3404", ieor3404);
courses.put("3658", ieor3658);
Expand Down Expand Up @@ -249,21 +251,29 @@ public void resetDataFile() {
mapping.put("ELEN", elen);

//data for psyc dept
Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200);
Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH",
"1:10-2:25", 200);
psyc1001.setEnrolledStudentCount(191);
Course psyc1610 = new Course("Christopher Baldassano", "200 SCH", times[2], 45);
Course psyc1610 = new Course("Christopher Baldassano", "200 SCH",
times[2], 45);
psyc1610.setEnrolledStudentCount(42);
Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH", times[0], 125);
Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH",
times[0], 125);
psyc2235.setEnrolledStudentCount(128);
Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS", "1:10-3:40", 60);
Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS",
"1:10-3:40", 60);
psyc2620.setEnrolledStudentCount(55);
Course psyc3212 = new Course("Mayron Piccolo", "200 SCH", "2:10-4:00", 15);
Course psyc3212 = new Course("Mayron Piccolo", "200 SCH",
"2:10-4:00", 15);
psyc3212.setEnrolledStudentCount(15);
Course psyc3445 = new Course("Mariam Aly", "405 SCH", "2:10-4:00", 12);
Course psyc3445 = new Course("Mariam Aly", "405 SCH",
"2:10-4:00", 12);
psyc3445.setEnrolledStudentCount(12);
Course psyc4236 = new Course("Trenton Jerde", "405 SCH", "6:10-8:00", 18);
Course psyc4236 = new Course("Trenton Jerde", "405 SCH",
"6:10-8:00", 18);
psyc4236.setEnrolledStudentCount(17);
Course psyc4493 = new Course("Jennifer Blaze", "200 SCH", "2:10-4:00", 15);
Course psyc4493 = new Course("Jennifer Blaze", "200 SCH",
"2:10-4:00", 15);
psyc4493.setEnrolledStudentCount(9);

courses = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package dev.coms4156.project.individualproject;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;

/**
* This class contains all the API routes for the system.
Expand Down Expand Up @@ -263,7 +269,8 @@ public ResponseEntity<?> findCourseInstructor(@RequestParam(value = "deptCode")
* indicating the proper response.
*/
@GetMapping(value = "/findCourseTime", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> findCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
public ResponseEntity<?> findCourseTime(@RequestParam(value = "deptCode") String deptCode,
@RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
Expand Down Expand Up @@ -451,7 +458,9 @@ public ResponseEntity<?> changeCourseTime(@RequestParam(value = "deptCode") Stri
* successful, or an error message if the course is not found
*/
@PatchMapping(value = "/changeCourseTeacher", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> changeCourseTeacher(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "teacher") String teacher) {
public ResponseEntity<?> changeCourseTeacher(@RequestParam(value = "deptCode") String deptCode,
@RequestParam(value = "courseCode") int courseCode,
@RequestParam(value = "teacher") String teacher) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
Expand All @@ -473,9 +482,23 @@ public ResponseEntity<?> changeCourseTeacher(@RequestParam(value = "deptCode") S
}
}


/**
* Endpoint for changing the location of a course.
* This method handles PATCH requests to change the instructor of a course identified by
* department code and course code. If the course exists, its instructor is updated to the
* provided instructor.
*
* @param deptCode the code of the department containing the course
* @param courseCode the code of the course to change the instructor for
* @param location the location to instruct the course
*
* @return a ResponseEntity with a success message if the operation is
* successful, or an error message if the course is not found
*/
@PatchMapping(value = "/changeCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> changeCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "location") String location) {
public ResponseEntity<?> changeCourseLocation(@RequestParam(value = "deptCode") String deptCode,
@RequestParam(value = "courseCode") int courseCode,
@RequestParam(value = "location") String location) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dev.coms4156.project.individualproject;

import org.junit.jupiter.api.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest
@ContextConfiguration
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Welcome Students of 4156

Please follow the assignment specifications on Courseworks when completing this project.

## modification of readme
Loading