From b5f30c21bd158aeecf5ac0f6b1b0699095fcc70a Mon Sep 17 00:00:00 2001 From: wayneSongwx Date: Thu, 12 Sep 2024 16:24:26 -0400 Subject: [PATCH 1/2] chore/add a line in readme.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 93e4ba9b..22751b15 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Welcome Students of 4156 Please follow the assignment specifications on Courseworks when completing this project. + +## modification of readme \ No newline at end of file From c03dcf6dd3f5f85703d0cbbd4a1e39f5df17332c Mon Sep 17 00:00:00 2001 From: wayneSongwx Date: Thu, 12 Sep 2024 23:02:30 -0400 Subject: [PATCH 2/2] chore:correct some of the format --- IndividualProject/data.txt | Bin 0 -> 3868 bytes IndividualProject/pom.xml | 9 +- .../project/individualproject/Course.java | 16 ++- .../project/individualproject/Department.java | 7 +- .../IndividualProjectApplication.java | 94 ++++++++++-------- .../individualproject/RouteController.java | 35 +++++-- .../individualproject/CourseUnitTests.java | 5 +- 7 files changed, 106 insertions(+), 60 deletions(-) create mode 100644 IndividualProject/data.txt diff --git a/IndividualProject/data.txt b/IndividualProject/data.txt new file mode 100644 index 0000000000000000000000000000000000000000..99f11c1548edcfaa4cbf97cecb78dc6703bd63ab GIT binary patch literal 3868 zcma)9OKc-q6|Hn9%HR2PtEbVx@DM_Rfu!r_UubE@vGcKGCm~KI3Lw!hu9vQtlmFug8PY zo0_=hQPLG*LZ*!SKi|1$OxBHD*z2B)=-{HoFI5ybjp>f+MX`tz<3W?ceL~?r8HW4K zrm^IuhN?c7QDUqP&ILSt{-m8mGJK9>GdPx1l_%aeeq>DDUc=?5F?~1wCz%-}fR5E%i!#Ih0RFr+*9ZTmexMztmYuRR=wN7d^e0Mi2bFHx9nu)Qr zC&Ex9K5P3#n1>{B($XBv0vh0Rn;6rMX|cnT!x1>YVdp`8jiY*OhrP!G@Jit(#F9H^ z;BzqW)x?-7+2xUY8=lvkjXW$Y?ukf*Y*R$fyBsy2bn}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>9zs#5xf72=62)LP-TWAbUjjn!oiBs9 zB8h)l3+Wqs(Oo~jOVkBPsgIFB!(u2Xm|DuscZnMmZE(ZWeSt_)2$shZ@RWGji@|Q=jZgJ1r@Z+Ob$LC0Y4eCvIr5lgU~-`r}*hc z$06-$e6;Eh5#ONTx*18Uuu&!3<|4e)Oc&0 NMd(a$LdX7o`(HnBpK$;H literal 0 HcmV?d00001 diff --git a/IndividualProject/pom.xml b/IndividualProject/pom.xml index 6d87d4c9..9ee6054e 100644 --- a/IndividualProject/pom.xml +++ b/IndividualProject/pom.xml @@ -27,6 +27,11 @@ spring-boot-starter-test test + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + @@ -80,8 +85,8 @@ org.apache.maven.plugins maven-compiler-plugin - 17 - 17 + 7 + 7 diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java index 272c94c9..5f279fcc 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java @@ -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 { /** @@ -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. diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java index 4bab0f08..c98ee691 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java @@ -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. diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java index 80860423..2423db89 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java @@ -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. * @@ -34,13 +36,13 @@ 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"); @@ -48,20 +50,20 @@ public void run(String[] args) { /** * 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); @@ -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); @@ -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<>(); diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java index 09f504dc..282283bb 100644 --- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java +++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java @@ -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. @@ -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; @@ -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; @@ -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; diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java index 4edd00f9..a0de776d 100644 --- a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java +++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java @@ -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