From 32a755a57862ef0f11019ff5169a24c836830331 Mon Sep 17 00:00:00 2001 From: Emma Eagles Date: Mon, 16 Mar 2020 18:33:38 -0400 Subject: [PATCH 1/5] route and creating notif page --- .../cooperator/config/FlywayConfig.java | 2 +- .../controller/ControllerUtils.java | 2 +- .../controller/NotificationController.java | 72 ++++++++ .../controller/BaseControllerIT.java | 24 +++ .../controller/NotificationControllerIT.java | 31 ++++ Frontend/src/layouts/AdminLoggedInLayout.vue | 6 - .../admin/AdminCreateNotificationPage.vue | 165 ++++++++++++++++++ .../src/pages/admin/AdminStudentsPage.vue | 30 +++- .../pages/admin/CreateNotificationPage.vue | 82 +++++++++ Frontend/src/router/routes.js | 6 + 10 files changed, 410 insertions(+), 10 deletions(-) create mode 100644 Frontend/src/pages/admin/AdminCreateNotificationPage.vue create mode 100644 Frontend/src/pages/admin/CreateNotificationPage.vue diff --git a/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java b/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java index 314e8f923..6413c0d8a 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java @@ -15,7 +15,7 @@ public FlywayMigrationStrategy cleanMigrateStrategy() { new FlywayMigrationStrategy() { @Override public void migrate(Flyway flyway) { - flyway.migrate(); + flyway.migrate(); } }; diff --git a/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java b/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java index 42556d082..d2aa71997 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java @@ -73,7 +73,7 @@ public static AdminDto convertToDto(Admin a) { notification.getTimeStamp()); Student student = notification.getStudent(); StudentDto studentDto = - new StudentDto( + new StudentDto( student.getId(), student.getFirstName(), student.getLastName(), diff --git a/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java b/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java index 1ed9bfd96..751444611 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java @@ -9,6 +9,7 @@ import ca.mcgill.cooperator.service.AdminService; import ca.mcgill.cooperator.service.NotificationService; import ca.mcgill.cooperator.service.StudentService; +import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; @@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @CrossOrigin(origins = "*") @@ -65,6 +67,76 @@ public NotificationDto createNotification(@RequestBody NotificationDto n) { return ControllerUtils.convertToDto(notification); } + /** + * Creates a new Notification + * + *

In request body: + * + * @param title + * @param body + * @param student + * @param sender + * @return the created Notification + */ + @PostMapping("/many") + public List createManyNotifications( + @RequestParam("studentIds") List stuIds, + @RequestParam("admin") Integer adminId, + @RequestParam("title") String title, + @RequestParam("body") String body) { + + Admin sender = null; + if (adminId != null) { + sender = adminService.getAdmin(adminId); + } + + Student student = null; + List notifs = new ArrayList<>(); + for (Integer id : stuIds) { + student = studentService.getStudentById(id); + Notification notification = + notificationService.createNotification(title, body, student, sender); + notifs.add(notification); + } + + return ControllerUtils.convertNotifListToDto(notifs); + } + + /** + * Creates a new Notification + * + *

In request body: + * + * @param title + * @param body + * @param student + * @param sender + * @return the created Notification + */ + @PostMapping("/many") + public List createManyNotifications( + @RequestParam("studentIds") List stuIds, + @RequestParam("admin") Integer adminId, + @RequestParam("title") String title, + @RequestParam("body") String body) { + + Admin sender = null; + if (adminId != null) { + sender = adminService.getAdmin(adminId); + } + + Student student = null; + List notifs = new ArrayList<>(); + for (Integer id : stuIds) { + student = studentService.getStudentById(id); + Notification notification = + notificationService.createNotification(title, body, student, sender); + notifs.add(notification); + } + + return ControllerUtils.convertNotifListToDto(notifs); + } + /** * Gets a Notification by ID * diff --git a/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java b/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java index 72a1e9579..8cd74bcfc 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java @@ -145,6 +145,30 @@ public StudentDto createTestStudent() throws Exception { return studentDto; } + + public StudentDto createTestStudent(String email, String stuId) throws Exception { + StudentDto studentDto = new StudentDto(); + studentDto.setEmail(email); + studentDto.setFirstName("Emma"); + studentDto.setLastName("Eagles"); + studentDto.setStudentId(stuId); + MvcResult mvcResult = + mvc.perform( + post("/students") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(studentDto)) + .characterEncoding("utf-8")) + .andExpect(status().isOk()) + .andReturn(); + + // get object from response + studentDto = + objectMapper.readValue( + mvcResult.getResponse().getContentAsString(), StudentDto.class); + + return studentDto; + } + public CoopDto createTestCoop( CourseOfferingDto courseOfferingDto, StudentDto studentDto, CoopStatus coopStatus) diff --git a/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java b/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java index 63a16bfec..d50a25737 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java @@ -212,4 +212,35 @@ public void testNotificationFlow() throws Exception { assertEquals(0, notifDtos.size()); } + + @Test + public void testManyNotificationsFlow() throws Exception { + StudentDto studentDto1 = createTestStudent("emma@eagles.ca", "123123123"); + StudentDto studentDto2 = createTestStudent("eagles@emma.ca", "321321321"); + AdminDto adminDto = createTestAdmin(); + + String title = "Hello"; + String body = "Please attend meeting."; + + + // 1. create notification + + MvcResult mvcResult = + mvc.perform( + post("/notifications/many?admin=" + adminDto.getId() + + "&title=" + title + "&body=" + body + "&studentIds=" + studentDto1.getId() +"," + studentDto2.getId()) + .contentType(MediaType.APPLICATION_JSON) + .characterEncoding("utf-8")) + .andExpect(status().isOk()) + .andReturn(); + + // get object from response + List notifDtos = + Arrays.asList( + objectMapper.readValue( + mvcResult.getResponse().getContentAsString(), + NotificationDto[].class)); + + assertEquals(2, notifDtos.size()); + } } diff --git a/Frontend/src/layouts/AdminLoggedInLayout.vue b/Frontend/src/layouts/AdminLoggedInLayout.vue index 08ceb42ba..4c96d8b25 100644 --- a/Frontend/src/layouts/AdminLoggedInLayout.vue +++ b/Frontend/src/layouts/AdminLoggedInLayout.vue @@ -16,12 +16,6 @@ ADMIN - - - 4 - - - diff --git a/Frontend/src/pages/admin/AdminCreateNotificationPage.vue b/Frontend/src/pages/admin/AdminCreateNotificationPage.vue new file mode 100644 index 000000000..c924963b2 --- /dev/null +++ b/Frontend/src/pages/admin/AdminCreateNotificationPage.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/Frontend/src/pages/admin/AdminStudentsPage.vue b/Frontend/src/pages/admin/AdminStudentsPage.vue index 068ebcdcf..378d4f724 100644 --- a/Frontend/src/pages/admin/AdminStudentsPage.vue +++ b/Frontend/src/pages/admin/AdminStudentsPage.vue @@ -37,8 +37,16 @@ + @@ -73,6 +81,7 @@ export default { } }, data: () => ({ + selected: [], students: [], courseNames: [], courseNameData: "", @@ -177,6 +186,15 @@ export default { goToStudentCoop() { this.$router.push("/admin/student-coops"); }, + sendNotif() { + this.$router.push({ + path: "/admin/notification", + name: "CreateNotif", + params: { + selected: this.selected + } + }); + }, clearFilter() { this.courseNameData = ""; this.termData = ""; @@ -217,4 +235,12 @@ export default { }; - + diff --git a/Frontend/src/pages/admin/CreateNotificationPage.vue b/Frontend/src/pages/admin/CreateNotificationPage.vue new file mode 100644 index 000000000..21ece52ec --- /dev/null +++ b/Frontend/src/pages/admin/CreateNotificationPage.vue @@ -0,0 +1,82 @@ + + + + + diff --git a/Frontend/src/router/routes.js b/Frontend/src/router/routes.js index 378f81a88..b2bc95a21 100644 --- a/Frontend/src/router/routes.js +++ b/Frontend/src/router/routes.js @@ -89,6 +89,12 @@ const routes = [ { path: "csv-parse", component: () => import("pages/admin/CsvParse.vue") + }, + { + path: "notification", + component: () => import("pages/admin/AdminCreateNotificationPage.vue"), + props: true, + name: "CreateNotif" } ] } From 0633ecd22063e6313bdfcb4bd7d314a0e3a9be84 Mon Sep 17 00:00:00 2001 From: Emma Eagles Date: Thu, 9 Apr 2020 14:37:38 -0400 Subject: [PATCH 2/5] formatted --- .../ca/mcgill/cooperator/config/FlywayConfig.java | 2 +- .../cooperator/controller/ControllerUtils.java | 2 +- .../cooperator/controller/BaseControllerIT.java | 3 +-- .../controller/NotificationControllerIT.java | 15 +++++++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java b/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java index 6413c0d8a..314e8f923 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/config/FlywayConfig.java @@ -15,7 +15,7 @@ public FlywayMigrationStrategy cleanMigrateStrategy() { new FlywayMigrationStrategy() { @Override public void migrate(Flyway flyway) { - flyway.migrate(); + flyway.migrate(); } }; diff --git a/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java b/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java index d2aa71997..42556d082 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/controller/ControllerUtils.java @@ -73,7 +73,7 @@ public static AdminDto convertToDto(Admin a) { notification.getTimeStamp()); Student student = notification.getStudent(); StudentDto studentDto = - new StudentDto( + new StudentDto( student.getId(), student.getFirstName(), student.getLastName(), diff --git a/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java b/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java index 8cd74bcfc..d0c80988d 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/controller/BaseControllerIT.java @@ -145,7 +145,7 @@ public StudentDto createTestStudent() throws Exception { return studentDto; } - + public StudentDto createTestStudent(String email, String stuId) throws Exception { StudentDto studentDto = new StudentDto(); studentDto.setEmail(email); @@ -168,7 +168,6 @@ public StudentDto createTestStudent(String email, String stuId) throws Exception return studentDto; } - public CoopDto createTestCoop( CourseOfferingDto courseOfferingDto, StudentDto studentDto, CoopStatus coopStatus) diff --git a/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java b/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java index d50a25737..265dfa927 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/controller/NotificationControllerIT.java @@ -212,7 +212,7 @@ public void testNotificationFlow() throws Exception { assertEquals(0, notifDtos.size()); } - + @Test public void testManyNotificationsFlow() throws Exception { StudentDto studentDto1 = createTestStudent("emma@eagles.ca", "123123123"); @@ -221,14 +221,21 @@ public void testManyNotificationsFlow() throws Exception { String title = "Hello"; String body = "Please attend meeting."; - // 1. create notification MvcResult mvcResult = mvc.perform( - post("/notifications/many?admin=" + adminDto.getId() - + "&title=" + title + "&body=" + body + "&studentIds=" + studentDto1.getId() +"," + studentDto2.getId()) + post("/notifications/many?admin=" + + adminDto.getId() + + "&title=" + + title + + "&body=" + + body + + "&studentIds=" + + studentDto1.getId() + + "," + + studentDto2.getId()) .contentType(MediaType.APPLICATION_JSON) .characterEncoding("utf-8")) .andExpect(status().isOk()) From bfc64629129d593c415dd9db412794521bb60232 Mon Sep 17 00:00:00 2001 From: Emma Eagles Date: Thu, 9 Apr 2020 14:42:54 -0400 Subject: [PATCH 3/5] im so bad at merging lmao --- .../controller/NotificationController.java | 44 ++----------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java b/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java index 751444611..7943a9d54 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/controller/NotificationController.java @@ -68,50 +68,14 @@ public NotificationDto createNotification(@RequestBody NotificationDto n) { } /** - * Creates a new Notification - * - *

In request body: - * - * @param title - * @param body - * @param student - * @param sender - * @return the created Notification - */ - @PostMapping("/many") - public List createManyNotifications( - @RequestParam("studentIds") List stuIds, - @RequestParam("admin") Integer adminId, - @RequestParam("title") String title, - @RequestParam("body") String body) { - - Admin sender = null; - if (adminId != null) { - sender = adminService.getAdmin(adminId); - } - - Student student = null; - List notifs = new ArrayList<>(); - for (Integer id : stuIds) { - student = studentService.getStudentById(id); - Notification notification = - notificationService.createNotification(title, body, student, sender); - notifs.add(notification); - } - - return ControllerUtils.convertNotifListToDto(notifs); - } - - /** - * Creates a new Notification + * Creates a new Notification for all the students in the list * - *

In request body: * * @param title * @param body - * @param student - * @param sender - * @return the created Notification + * @param list of student Ids + * @param sender Id + * @return list of the created Notifications */ @PostMapping("/many") public List createManyNotifications( From 56656c8eda3cdef6b3f6063ea6b6414d84363120 Mon Sep 17 00:00:00 2001 From: Emma Eagles Date: Thu, 9 Apr 2020 15:41:22 -0400 Subject: [PATCH 4/5] PR comments --- .../admin/AdminCreateNotificationPage.vue | 71 +++++++++------- .../src/pages/admin/AdminStudentsPage.vue | 11 +-- .../pages/admin/CreateNotificationPage.vue | 82 ------------------- Frontend/src/router/routes.js | 2 +- 4 files changed, 47 insertions(+), 119 deletions(-) delete mode 100644 Frontend/src/pages/admin/CreateNotificationPage.vue diff --git a/Frontend/src/pages/admin/AdminCreateNotificationPage.vue b/Frontend/src/pages/admin/AdminCreateNotificationPage.vue index c924963b2..623af1800 100644 --- a/Frontend/src/pages/admin/AdminCreateNotificationPage.vue +++ b/Frontend/src/pages/admin/AdminCreateNotificationPage.vue @@ -1,37 +1,46 @@ - - diff --git a/Frontend/src/router/routes.js b/Frontend/src/router/routes.js index b2bc95a21..0b86befc4 100644 --- a/Frontend/src/router/routes.js +++ b/Frontend/src/router/routes.js @@ -91,7 +91,7 @@ const routes = [ component: () => import("pages/admin/CsvParse.vue") }, { - path: "notification", + path: "create-notification", component: () => import("pages/admin/AdminCreateNotificationPage.vue"), props: true, name: "CreateNotif" From 2371f2b32e5a4c77ce9e4c6dbf6cdacbbd40289e Mon Sep 17 00:00:00 2001 From: Emma Eagles Date: Fri, 10 Apr 2020 13:01:27 -0400 Subject: [PATCH 5/5] pr comments --- .../pages/admin/AdminCreateNotificationPage.vue | 15 +++++++++++++-- Frontend/src/pages/admin/AdminNotifications.vue | 12 ------------ Frontend/src/router/routes.js | 14 ++++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 Frontend/src/pages/admin/AdminNotifications.vue diff --git a/Frontend/src/pages/admin/AdminCreateNotificationPage.vue b/Frontend/src/pages/admin/AdminCreateNotificationPage.vue index 623af1800..2890a3cb3 100644 --- a/Frontend/src/pages/admin/AdminCreateNotificationPage.vue +++ b/Frontend/src/pages/admin/AdminCreateNotificationPage.vue @@ -24,11 +24,19 @@ class="notifPageComponents" /> + + @@ -50,6 +58,7 @@ export default { name: "HomeMainInfo", data: () => ({ + sending: false, tableStudents: [], toSendTo: [], body: "", @@ -112,7 +121,7 @@ export default { }, methods: { goToStudentCoop() { - this.$router.push("/admin/studentcoops"); + this.$router.push("/admin/student-coops"); }, sendNotification() { var adminId = this.$store.state.currentUser.id; @@ -120,7 +129,7 @@ export default { for (var i = 0; i < this.toSendTo.length; i++) { stuIds.push(this.toSendTo[i].id); } - + this.sending = true; // create the notification this.$axios .post( @@ -134,6 +143,7 @@ export default { stuIds ) .then(_resp => { + this.sending = false; this.body = ""; this.title = ""; this.toSendTo = []; @@ -146,6 +156,7 @@ export default { }); }) .catch(_err => { + this.sending = false; this.$q.notify({ color: "red-4", position: "top", diff --git a/Frontend/src/pages/admin/AdminNotifications.vue b/Frontend/src/pages/admin/AdminNotifications.vue deleted file mode 100644 index 4d5b2f74d..000000000 --- a/Frontend/src/pages/admin/AdminNotifications.vue +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/Frontend/src/router/routes.js b/Frontend/src/router/routes.js index 0b86befc4..40264d161 100644 --- a/Frontend/src/router/routes.js +++ b/Frontend/src/router/routes.js @@ -44,8 +44,14 @@ const routes = [ component: () => import("layouts/AdminLoggedInLayout.vue"), meta: { requiresAdminAuth: true }, children: [ - { path: "", redirect: "home" }, - { path: "home", component: () => import("pages/admin/AdminHome.vue") }, + { + path: "", + redirect: "home" + }, + { + path: "home", + component: () => import("pages/admin/AdminHome.vue") + }, { path: "student-coops", component: () => import("pages/admin/AdminStudentCoops.vue") @@ -78,10 +84,6 @@ const routes = [ path: "companies", component: () => import("pages/admin/AdminCompanies.vue") }, - { - path: "notifications", - component: () => import("pages/admin/AdminNotifications.vue") - }, { path: "report-config", component: () => import("pages/admin/AdminReportConfigPage.vue")