From 3aadc3eb22c15f48eb3506c430e6f5e6eea2641e Mon Sep 17 00:00:00 2001 From: gemj98 Date: Wed, 10 Apr 2024 23:53:10 -0700 Subject: [PATCH 1/7] MongoDB integration - Add Lombok dependecy for reducing code on class definitions - Add mongoDB to spring app - Created packages for models, controllers, repository and services. - Add Notification functionality. --- back_end/build.gradle.kts | 9 ++++++ .../Cmpe202FinalApplication.java | 8 +++++- .../controller/NotificationController.java | 28 +++++++++++++++++++ .../cmpe202_final/model/Notification.java | 28 +++++++++++++++++++ .../repository/NotificationRepository.java | 11 ++++++++ .../service/NotificationService.java | 21 ++++++++++++++ .../src/main/resources/application.properties | 4 +++ 7 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 back_end/src/main/java/org/example/cmpe202_final/controller/NotificationController.java create mode 100644 back_end/src/main/java/org/example/cmpe202_final/model/Notification.java create mode 100644 back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java create mode 100644 back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java diff --git a/back_end/build.gradle.kts b/back_end/build.gradle.kts index edfbe4a6..82357695 100644 --- a/back_end/build.gradle.kts +++ b/back_end/build.gradle.kts @@ -30,6 +30,8 @@ repositories { dependencies { implementation("org.springframework.boot:spring-boot-starter-web") + // Add-on for MongoDB + implementation("org.springframework.boot:spring-boot-starter-data-mongodb") testImplementation("org.springframework.boot:spring-boot-starter-test") // JUnit Jupiter for testing testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") @@ -37,6 +39,13 @@ dependencies { testImplementation("org.springframework.boot:spring-boot-starter-test") // Mocking framework testImplementation("org.mockito:mockito-core:4.0.0") + + // Lombok to reduce repetitive code such as getters and setters + compileOnly("org.projectlombok:lombok:1.18.32") + annotationProcessor("org.projectlombok:lombok:1.18.32") + + testCompileOnly("org.projectlombok:lombok:1.18.32") + testAnnotationProcessor("org.projectlombok:lombok:1.18.32") } tasks.withType { diff --git a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java index 833e5ab4..fda7b1e8 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java +++ b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java @@ -1,12 +1,18 @@ package org.example.cmpe202_final; +import org.example.cmpe202_final.model.Notification; +import org.example.cmpe202_final.repository.NotificationRepository; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +import java.time.LocalDateTime; + @SpringBootApplication public class Cmpe202FinalApplication { @@ -14,7 +20,7 @@ public static void main(String[] args) { SpringApplication.run(Cmpe202FinalApplication.class, args); } - + @RestController public static class AdminController { diff --git a/back_end/src/main/java/org/example/cmpe202_final/controller/NotificationController.java b/back_end/src/main/java/org/example/cmpe202_final/controller/NotificationController.java new file mode 100644 index 00000000..ad431a0c --- /dev/null +++ b/back_end/src/main/java/org/example/cmpe202_final/controller/NotificationController.java @@ -0,0 +1,28 @@ +package org.example.cmpe202_final.controller; + +import lombok.AllArgsConstructor; +import org.example.cmpe202_final.model.Notification; +import org.example.cmpe202_final.service.NotificationService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/notifications") +@AllArgsConstructor +public class NotificationController { + private final NotificationService notificationService; + + @GetMapping + public List fetchAllNotifications() { + return notificationService.getAllNotifications(); + } + + @PostMapping + public void insertNewNotification(Notification notification) { + notificationService.insertNotification(notification); + } +} diff --git a/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java b/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java new file mode 100644 index 00000000..89480408 --- /dev/null +++ b/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java @@ -0,0 +1,28 @@ +package org.example.cmpe202_final.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.time.LocalDateTime; + +@Data +@Document +public class Notification { + @Id + private String id; + private String courseName; + private String eventTitle; + private String eventId; + private LocalDateTime date; + private String type; + + public Notification(String courseName, String eventTitle, String eventId, LocalDateTime date, String type) { + this.courseName = courseName; + this.eventTitle = eventTitle; + this.eventId = eventId; + this.date = date; + this.type = type; + } +} diff --git a/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java b/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java new file mode 100644 index 00000000..a5424a23 --- /dev/null +++ b/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java @@ -0,0 +1,11 @@ +package org.example.cmpe202_final.repository; + +import org.example.cmpe202_final.model.Notification; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.List; + +public interface NotificationRepository extends MongoRepository { + List findAllByOrderByDate(); + +} diff --git a/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java b/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java new file mode 100644 index 00000000..442893a7 --- /dev/null +++ b/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java @@ -0,0 +1,21 @@ +package org.example.cmpe202_final.service; + +import lombok.AllArgsConstructor; +import org.example.cmpe202_final.model.Notification; +import org.example.cmpe202_final.repository.NotificationRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +@AllArgsConstructor +@Service +public class NotificationService { + private final NotificationRepository repository; + public List getAllNotifications() { + return repository.findAllByOrderByDate(); + } + + public void insertNotification(Notification notification) { + repository.save(notification); + } +} diff --git a/back_end/src/main/resources/application.properties b/back_end/src/main/resources/application.properties index 33406d21..363fdf64 100644 --- a/back_end/src/main/resources/application.properties +++ b/back_end/src/main/resources/application.properties @@ -1 +1,5 @@ spring.main.banner-mode=off + +spring.data.mongodb.uri=mongodb+srv://general-user:general-user@studentportal.vsxqunp.mongodb.net/ +spring.data.mongodb.database=student_portal +spring.data.mongodb.auto-index-creation=true \ No newline at end of file From 0050b5eea0e3fe9a8622b1eb7bc3cde1662f6f3b Mon Sep 17 00:00:00 2001 From: gemj98 Date: Thu, 11 Apr 2024 06:05:18 -0700 Subject: [PATCH 2/7] Add tests for Notification --- .../cmpe202_final/model/Notification.java | 3 + .../repository/NotificationRepository.java | 2 +- .../service/NotificationService.java | 2 +- .../NotificationControllerTest.java | 89 +++++++++++++++++++ .../NotificationRepositoryTest.java | 50 +++++++++++ .../service/NotificationServiceTest.java | 52 +++++++++++ 6 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 back_end/src/test/java/org/example/cmpe202_final/controller/NotificationControllerTest.java create mode 100644 back_end/src/test/java/org/example/cmpe202_final/repository/NotificationRepositoryTest.java create mode 100644 back_end/src/test/java/org/example/cmpe202_final/service/NotificationServiceTest.java diff --git a/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java b/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java index 89480408..4e65a7c1 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java +++ b/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java @@ -2,6 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -9,6 +10,8 @@ @Data @Document +@NoArgsConstructor +@AllArgsConstructor public class Notification { @Id private String id; diff --git a/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java b/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java index a5424a23..d5e8757f 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java +++ b/back_end/src/main/java/org/example/cmpe202_final/repository/NotificationRepository.java @@ -6,6 +6,6 @@ import java.util.List; public interface NotificationRepository extends MongoRepository { - List findAllByOrderByDate(); + List findAllByOrderByDateDesc(); } diff --git a/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java b/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java index 442893a7..9b682fa9 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java +++ b/back_end/src/main/java/org/example/cmpe202_final/service/NotificationService.java @@ -12,7 +12,7 @@ public class NotificationService { private final NotificationRepository repository; public List getAllNotifications() { - return repository.findAllByOrderByDate(); + return repository.findAllByOrderByDateDesc(); } public void insertNotification(Notification notification) { diff --git a/back_end/src/test/java/org/example/cmpe202_final/controller/NotificationControllerTest.java b/back_end/src/test/java/org/example/cmpe202_final/controller/NotificationControllerTest.java new file mode 100644 index 00000000..28e6a675 --- /dev/null +++ b/back_end/src/test/java/org/example/cmpe202_final/controller/NotificationControllerTest.java @@ -0,0 +1,89 @@ +package org.example.cmpe202_final.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.example.cmpe202_final.model.Notification; +import org.example.cmpe202_final.service.NotificationService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(NotificationController.class) +public class NotificationControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private NotificationService notificationService; + + @Autowired + private ObjectMapper objectMapper; + + @BeforeEach + void setUp() { + // Set up any necessary test data here + } + + @Test + void testFetchAllNotifications() throws Exception { + // Given + Notification notification1 = new Notification( + "1", + "CMPE 202", + "Quiz 1", + "1", + LocalDateTime.now(), + "ASSIGNMENT_CREATED" + ); + Notification notification2 = new Notification( + "2", + "CMPE 202", + "Quiz 2", + "2", + LocalDateTime.now(), + "ASSIGNMENT_GRADED" + ); + List notifications = Arrays.asList(notification1, notification2); + given(notificationService.getAllNotifications()).willReturn(notifications); + + // When & Then + mockMvc.perform(get("/notifications") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(notifications))); + } + + @Test + void testInsertNewNotification() throws Exception { + // Given + Notification notification = new Notification( + "1", + "CMPE 202", + "Quiz 1", + "1", + LocalDateTime.now(), + "ASSIGNMENT_CREATED" + ); + String notificationJson = objectMapper.writeValueAsString(notification); + + // When & Then + mockMvc.perform(post("/notifications") + .contentType(MediaType.APPLICATION_JSON) + .content(notificationJson)) + .andExpect(status().isOk()); + } +} diff --git a/back_end/src/test/java/org/example/cmpe202_final/repository/NotificationRepositoryTest.java b/back_end/src/test/java/org/example/cmpe202_final/repository/NotificationRepositoryTest.java new file mode 100644 index 00000000..838bf1c3 --- /dev/null +++ b/back_end/src/test/java/org/example/cmpe202_final/repository/NotificationRepositoryTest.java @@ -0,0 +1,50 @@ +package org.example.cmpe202_final.repository; + +import org.example.cmpe202_final.model.Notification; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; + +import java.time.LocalDateTime; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +@DataMongoTest +public class NotificationRepositoryTest { + + @Autowired + private NotificationRepository notificationRepository; + + @BeforeEach + void setUp() { + // Ensure the repository is empty before each test + notificationRepository.deleteAll(); + + // Prepare test data + Notification notification1 = new Notification("1", "Course 1", "Event 1", "1", LocalDateTime.now().minusDays(1), "Type A"); + Notification notification2 = new Notification("2", "Course 2", "Event 2", "2", LocalDateTime.now(), "Type B"); + Notification notification3 = new Notification("3", "Course 3", "Event 3", "3", LocalDateTime.now().minusDays(2), "Type A"); + + // Save test notifications + notificationRepository.save(notification1); + notificationRepository.save(notification2); + notificationRepository.save(notification3); + } + + @Test + void testFindAllByOrderByDate() { + List notifications = notificationRepository.findAllByOrderByDateDesc(); + + assertThat(notifications).isNotNull(); + assertThat(notifications.size()).isEqualTo(3); + + // Verify the order is correct based on date + LocalDateTime previousDate = LocalDateTime.MAX; + for (Notification notification : notifications) { + assertThat(notification.getDate()).isBeforeOrEqualTo(previousDate); + previousDate = notification.getDate(); + } + } +} diff --git a/back_end/src/test/java/org/example/cmpe202_final/service/NotificationServiceTest.java b/back_end/src/test/java/org/example/cmpe202_final/service/NotificationServiceTest.java new file mode 100644 index 00000000..505afc23 --- /dev/null +++ b/back_end/src/test/java/org/example/cmpe202_final/service/NotificationServiceTest.java @@ -0,0 +1,52 @@ +package org.example.cmpe202_final.service; + +import org.example.cmpe202_final.model.Notification; +import org.example.cmpe202_final.repository.NotificationRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; + +public class NotificationServiceTest { + + @Mock + private NotificationRepository notificationRepository; + + @InjectMocks + private NotificationService notificationService; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + public void testGetAllNotifications() { + Notification notification1 = new Notification("Course 1", "Event 1", "1", LocalDateTime.now().minusDays(1), "Type A"); + Notification notification2 = new Notification("Course 2", "Event 2", "2", LocalDateTime.now(), "Type B"); + List expectedNotifications = Arrays.asList(notification2, notification1); + + when(notificationRepository.findAllByOrderByDateDesc()).thenReturn(expectedNotifications); + + List actualNotifications = notificationService.getAllNotifications(); + + assertThat(actualNotifications).isEqualTo(expectedNotifications); + verify(notificationRepository).findAllByOrderByDateDesc(); + } + + @Test + public void testInsertNotification() { + Notification newNotification = new Notification("Course 3", "Event 3", "3", LocalDateTime.now(), "Type C"); + + notificationService.insertNotification(newNotification); + + verify(notificationRepository).save(newNotification); + } +} From f5c7c568993f78c00a65ad658e07aaafeb32afcc Mon Sep 17 00:00:00 2001 From: gemj98 Date: Thu, 11 Apr 2024 06:14:07 -0700 Subject: [PATCH 3/7] Add test for Notification class --- .../Cmpe202FinalApplication.java | 5 --- .../cmpe202_final/model/NotificationTest.java | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 back_end/src/test/java/org/example/cmpe202_final/model/NotificationTest.java diff --git a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java index fda7b1e8..2f2940cb 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java +++ b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java @@ -1,17 +1,12 @@ package org.example.cmpe202_final; -import org.example.cmpe202_final.model.Notification; -import org.example.cmpe202_final.repository.NotificationRepository; -import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; -import java.time.LocalDateTime; @SpringBootApplication public class Cmpe202FinalApplication { diff --git a/back_end/src/test/java/org/example/cmpe202_final/model/NotificationTest.java b/back_end/src/test/java/org/example/cmpe202_final/model/NotificationTest.java new file mode 100644 index 00000000..757a7899 --- /dev/null +++ b/back_end/src/test/java/org/example/cmpe202_final/model/NotificationTest.java @@ -0,0 +1,41 @@ +package org.example.cmpe202_final.model; + +import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; +import static org.junit.jupiter.api.Assertions.*; + +class NotificationTest { + + @Test + void testConstructorAndGetter() { + LocalDateTime now = LocalDateTime.now(); + Notification notification = new Notification("Math101", "Exam", "E1", now, "INFO"); + + assertAll("constructor", + () -> assertEquals("Math101", notification.getCourseName()), + () -> assertEquals("Exam", notification.getEventTitle()), + () -> assertEquals("E1", notification.getEventId()), + () -> assertEquals(now, notification.getDate()), + () -> assertEquals("INFO", notification.getType()) + ); + } + + @Test + void testSetterAndGetter() { + LocalDateTime now = LocalDateTime.now(); + Notification notification = new Notification(); + notification.setCourseName("Math101"); + notification.setEventTitle("Exam"); + notification.setEventId("E1"); + notification.setDate(now); + notification.setType("INFO"); + + assertAll("setter and getter", + () -> assertEquals("Math101", notification.getCourseName()), + () -> assertEquals("Exam", notification.getEventTitle()), + () -> assertEquals("E1", notification.getEventId()), + () -> assertEquals(now, notification.getDate()), + () -> assertEquals("INFO", notification.getType()) + ); + } +} From 4c4533cc36e86df1324da77fc566602371377e7b Mon Sep 17 00:00:00 2001 From: gemj98 Date: Thu, 11 Apr 2024 06:22:31 -0700 Subject: [PATCH 4/7] Testing test coverage Commenting untested controllers --- .../Cmpe202FinalApplication.java | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java index 2f2940cb..8cf22018 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java +++ b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java @@ -16,108 +16,108 @@ public static void main(String[] args) { } - @RestController - public static class AdminController { - - @GetMapping("/admins/{id}") - public ResponseEntity getAdminById(@PathVariable int id) { - // Simulated data retrieval logic - if (id == 999) { // Assume 999 is an ID that does not exist - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Admin(id, "Admin Jane", "adminjane@example.com")); - } - } - } - - @RestController - public static class FacultyController { - - @GetMapping("/faculties/{id}") - public ResponseEntity getFacultyById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Faculty(id, "Faculty John", "facultyjohn@example.com")); - } - } - } - - @RestController - public static class StudentController { - - @GetMapping("/students/{id}") - public ResponseEntity getStudentById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Student(id, "Student Jane", "studentjane@example.com")); - } - } - } - - @RestController - public static class CourseController { - - @GetMapping("/courses/{id}") - public ResponseEntity getCourseById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Course(id, "Course 101", "Introduction to Java", "Spring 2024", true, null, null, null, null, null)); - } - } - } - - @RestController - public static class AssignmentController { - - @GetMapping("/assignments/{id}") - public ResponseEntity getAssignmentById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Assignment(id, "Assignment content", null, "2024-04-01", 100)); - } - } - } - - @RestController - public static class QuizController { - - @GetMapping("/quizzes/{id}") - public ResponseEntity getQuizById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Quiz(id, "Quiz content", null, null)); - } - } - } - - @RestController - public static class AnnouncementController { - - @GetMapping("/announcements/{id}") - public ResponseEntity getAnnouncementById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Announcement(id, "Announcement message", new java.util.Date(), null)); - } - } - } - - @RestController - public static class GradeController { - - @GetMapping("/grades/{id}") - public ResponseEntity getGradeById(@PathVariable int id) { - if (id == 999) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(new Grade(id, null, null, 95.0)); - } - } - } +// @RestController +// public static class AdminController { +// +// @GetMapping("/admins/{id}") +// public ResponseEntity getAdminById(@PathVariable int id) { +// // Simulated data retrieval logic +// if (id == 999) { // Assume 999 is an ID that does not exist +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Admin(id, "Admin Jane", "adminjane@example.com")); +// } +// } +// } +// +// @RestController +// public static class FacultyController { +// +// @GetMapping("/faculties/{id}") +// public ResponseEntity getFacultyById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Faculty(id, "Faculty John", "facultyjohn@example.com")); +// } +// } +// } +// +// @RestController +// public static class StudentController { +// +// @GetMapping("/students/{id}") +// public ResponseEntity getStudentById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Student(id, "Student Jane", "studentjane@example.com")); +// } +// } +// } +// +// @RestController +// public static class CourseController { +// +// @GetMapping("/courses/{id}") +// public ResponseEntity getCourseById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Course(id, "Course 101", "Introduction to Java", "Spring 2024", true, null, null, null, null, null)); +// } +// } +// } +// +// @RestController +// public static class AssignmentController { +// +// @GetMapping("/assignments/{id}") +// public ResponseEntity getAssignmentById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Assignment(id, "Assignment content", null, "2024-04-01", 100)); +// } +// } +// } +// +// @RestController +// public static class QuizController { +// +// @GetMapping("/quizzes/{id}") +// public ResponseEntity getQuizById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Quiz(id, "Quiz content", null, null)); +// } +// } +// } +// +// @RestController +// public static class AnnouncementController { +// +// @GetMapping("/announcements/{id}") +// public ResponseEntity getAnnouncementById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Announcement(id, "Announcement message", new java.util.Date(), null)); +// } +// } +// } +// +// @RestController +// public static class GradeController { +// +// @GetMapping("/grades/{id}") +// public ResponseEntity getGradeById(@PathVariable int id) { +// if (id == 999) { +// return ResponseEntity.notFound().build(); +// } else { +// return ResponseEntity.ok(new Grade(id, null, null, 95.0)); +// } +// } +// } } From b53f82a67284d9af501a03aa922d9fd674980fd5 Mon Sep 17 00:00:00 2001 From: gemj98 Date: Thu, 11 Apr 2024 06:26:43 -0700 Subject: [PATCH 5/7] Undo Testing test coverage --- .../Cmpe202FinalApplication.java | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java index 8cf22018..2f2940cb 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java +++ b/back_end/src/main/java/org/example/cmpe202_final/Cmpe202FinalApplication.java @@ -16,108 +16,108 @@ public static void main(String[] args) { } -// @RestController -// public static class AdminController { -// -// @GetMapping("/admins/{id}") -// public ResponseEntity getAdminById(@PathVariable int id) { -// // Simulated data retrieval logic -// if (id == 999) { // Assume 999 is an ID that does not exist -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Admin(id, "Admin Jane", "adminjane@example.com")); -// } -// } -// } -// -// @RestController -// public static class FacultyController { -// -// @GetMapping("/faculties/{id}") -// public ResponseEntity getFacultyById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Faculty(id, "Faculty John", "facultyjohn@example.com")); -// } -// } -// } -// -// @RestController -// public static class StudentController { -// -// @GetMapping("/students/{id}") -// public ResponseEntity getStudentById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Student(id, "Student Jane", "studentjane@example.com")); -// } -// } -// } -// -// @RestController -// public static class CourseController { -// -// @GetMapping("/courses/{id}") -// public ResponseEntity getCourseById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Course(id, "Course 101", "Introduction to Java", "Spring 2024", true, null, null, null, null, null)); -// } -// } -// } -// -// @RestController -// public static class AssignmentController { -// -// @GetMapping("/assignments/{id}") -// public ResponseEntity getAssignmentById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Assignment(id, "Assignment content", null, "2024-04-01", 100)); -// } -// } -// } -// -// @RestController -// public static class QuizController { -// -// @GetMapping("/quizzes/{id}") -// public ResponseEntity getQuizById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Quiz(id, "Quiz content", null, null)); -// } -// } -// } -// -// @RestController -// public static class AnnouncementController { -// -// @GetMapping("/announcements/{id}") -// public ResponseEntity getAnnouncementById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Announcement(id, "Announcement message", new java.util.Date(), null)); -// } -// } -// } -// -// @RestController -// public static class GradeController { -// -// @GetMapping("/grades/{id}") -// public ResponseEntity getGradeById(@PathVariable int id) { -// if (id == 999) { -// return ResponseEntity.notFound().build(); -// } else { -// return ResponseEntity.ok(new Grade(id, null, null, 95.0)); -// } -// } -// } + @RestController + public static class AdminController { + + @GetMapping("/admins/{id}") + public ResponseEntity getAdminById(@PathVariable int id) { + // Simulated data retrieval logic + if (id == 999) { // Assume 999 is an ID that does not exist + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Admin(id, "Admin Jane", "adminjane@example.com")); + } + } + } + + @RestController + public static class FacultyController { + + @GetMapping("/faculties/{id}") + public ResponseEntity getFacultyById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Faculty(id, "Faculty John", "facultyjohn@example.com")); + } + } + } + + @RestController + public static class StudentController { + + @GetMapping("/students/{id}") + public ResponseEntity getStudentById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Student(id, "Student Jane", "studentjane@example.com")); + } + } + } + + @RestController + public static class CourseController { + + @GetMapping("/courses/{id}") + public ResponseEntity getCourseById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Course(id, "Course 101", "Introduction to Java", "Spring 2024", true, null, null, null, null, null)); + } + } + } + + @RestController + public static class AssignmentController { + + @GetMapping("/assignments/{id}") + public ResponseEntity getAssignmentById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Assignment(id, "Assignment content", null, "2024-04-01", 100)); + } + } + } + + @RestController + public static class QuizController { + + @GetMapping("/quizzes/{id}") + public ResponseEntity getQuizById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Quiz(id, "Quiz content", null, null)); + } + } + } + + @RestController + public static class AnnouncementController { + + @GetMapping("/announcements/{id}") + public ResponseEntity getAnnouncementById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Announcement(id, "Announcement message", new java.util.Date(), null)); + } + } + } + + @RestController + public static class GradeController { + + @GetMapping("/grades/{id}") + public ResponseEntity getGradeById(@PathVariable int id) { + if (id == 999) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(new Grade(id, null, null, 95.0)); + } + } + } } From 650d66c9779491cf2c8003f755fb66e420daae48 Mon Sep 17 00:00:00 2001 From: gemj98 Date: Thu, 11 Apr 2024 06:41:37 -0700 Subject: [PATCH 6/7] Edit lombok annotations for Notification --- .../org/example/cmpe202_final/model/Notification.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java b/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java index 4e65a7c1..3a923673 100644 --- a/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java +++ b/back_end/src/main/java/org/example/cmpe202_final/model/Notification.java @@ -1,17 +1,16 @@ package org.example.cmpe202_final.model; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import java.time.LocalDateTime; -@Data -@Document +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Document public class Notification { @Id private String id; From e7c9bf447b794234b38cd2c34d3f1c071764f772 Mon Sep 17 00:00:00 2001 From: gemj98 Date: Thu, 11 Apr 2024 06:55:36 -0700 Subject: [PATCH 7/7] Create testfile.txt Just to trigger GitHub checks again --- .../app/src/main/java/com/example/studentportal/testfile.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 front_end/app/src/main/java/com/example/studentportal/testfile.txt diff --git a/front_end/app/src/main/java/com/example/studentportal/testfile.txt b/front_end/app/src/main/java/com/example/studentportal/testfile.txt new file mode 100644 index 00000000..e69de29b