diff --git a/src/main/java/com/pawwithu/connectdog/domain/fcm/service/FcmService.java b/src/main/java/com/pawwithu/connectdog/domain/fcm/service/FcmService.java index b0c8393c..de96744e 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/fcm/service/FcmService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/fcm/service/FcmService.java @@ -101,81 +101,85 @@ public String makeMessage(String targetToken, String title, String body) throws public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, String image, NotificationType notificationType, String title, String body) { - try { - String message = makeMessage(targetToken, title, body); - - OkHttpClient client = new OkHttpClient(); - RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); - - Request request = new Request.Builder() - .url(FIREBASE_API_URL) - .post(requestBody) - .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) - .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") - .build(); - - Response response = client.newCall(request).execute(); - - // 알림 저장 - volunteerNotificationRepository.save( - VolunteerNotification.builder() - .image(image) - .notificationType(notificationType) - .title(title) - .body(body) - .volunteer(volunteer) - .isRead(false) - .build() - ); - - if (!response.isSuccessful()) { - log.error("FCM 푸시 알람 전송이 실패했습니다. 응답 코드: {}\n{}", response.code(), response.body().string()); + if (volunteer.getNotification()) { + try { + String message = makeMessage(targetToken, title, body); + + OkHttpClient client = new OkHttpClient(); + RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); + + Request request = new Request.Builder() + .url(FIREBASE_API_URL) + .post(requestBody) + .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) + .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") + .build(); + + Response response = client.newCall(request).execute(); + + if (!response.isSuccessful()) { + log.error("FCM 푸시 알람 전송이 실패했습니다. 응답 코드: {}\n{}", response.code(), response.body().string()); + } + } catch (Exception e) { + log.error("Fcm 푸시 알람을 전송하는 도중에 에러가 발생했습니다. {}", e.getMessage()); + throw new BadRequestException(NOTIFICATION_SEND_ERROR); } } - catch (Exception e) { - log.error("Fcm 푸시 알람을 전송하는 도중에 에러가 발생했습니다. {}", e.getMessage()); - throw new BadRequestException(NOTIFICATION_SEND_ERROR); - } + + // 알림 저장 + volunteerNotificationRepository.save( + VolunteerNotification.builder() + .image(image) + .notificationType(notificationType) + .title(title) + .body(body) + .volunteer(volunteer) + .isRead(false) + .build() + ); + } public void sendMessageToIntermediary(String targetToken, Intermediary intermediary, String image, NotificationType notificationType, String title, String body) { - try { - String message = makeMessage(targetToken, title, body); - - OkHttpClient client = new OkHttpClient(); - RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); - - Request request = new Request.Builder() - .url(FIREBASE_API_URL) - .post(requestBody) - .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) - .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") - .build(); - - Response response = client.newCall(request).execute(); - - // 알림 저장 - intermediaryNotificationRepository.save( - IntermediaryNotification.builder() - .image(image) - .notificationType(notificationType) - .title(title) - .body(body) - .intermediary(intermediary) - .isRead(false) - .build() - ); - - if (!response.isSuccessful()) { - log.error("FCM 푸시 알람 전송이 실패했습니다. 응답 코드: {}\n{}", response.code(), response.body().string()); + if (intermediary.getNotification()) { + try { + String message = makeMessage(targetToken, title, body); + + OkHttpClient client = new OkHttpClient(); + RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); + + Request request = new Request.Builder() + .url(FIREBASE_API_URL) + .post(requestBody) + .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) + .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") + .build(); + + Response response = client.newCall(request).execute(); + + if (!response.isSuccessful()) { + log.error("FCM 푸시 알람 전송이 실패했습니다. 응답 코드: {}\n{}", response.code(), response.body().string()); + } + } catch (Exception e) { + log.error("Fcm 푸시 알람을 전송하는 도중에 에러가 발생했습니다. {}", e.getMessage()); + throw new BadRequestException(NOTIFICATION_SEND_ERROR); } } - catch (Exception e) { - log.error("Fcm 푸시 알람을 전송하는 도중에 에러가 발생했습니다. {}", e.getMessage()); - throw new BadRequestException(NOTIFICATION_SEND_ERROR); - } + + // 알림 저장 + intermediaryNotificationRepository.save( + IntermediaryNotification.builder() + .image(image) + .notificationType(notificationType) + .title(title) + .body(body) + .intermediary(intermediary) + .isRead(false) + .build() + ); + } public void saveVolunteerFcm(String email, VolunteerFcmRequest request) { diff --git a/src/main/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryController.java b/src/main/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryController.java index 874dd1fc..1d323753 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryController.java +++ b/src/main/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryController.java @@ -165,4 +165,27 @@ public ResponseEntity changePassword(@AuthenticationPrincipal UserDetails return ResponseEntity.noContent().build(); } + @Operation(summary = "설정 - 모집자 알림 설정", description = "모집자 알림을 설정합니다.", + responses = {@ApiResponse(responseCode = "204", description = "모집자 알림 설정 성공") + , @ApiResponse(responseCode = "400" + , description = "M1, 해당 이동봉사 중개를 찾을 수 없습니다." + , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @PatchMapping("/intermediaries/notification/setting") + public ResponseEntity changeNotification(@AuthenticationPrincipal UserDetails loginUser) { + intermediaryService.changeNotification(loginUser.getUsername()); + return ResponseEntity.noContent().build(); + } + + @Operation(summary = "설정 - 모집자 알림 설정 조회", description = "모집자 알림 설정을 조회합니다.", + responses = {@ApiResponse(responseCode = "204", description = "모집자 알림 설정 조회 성공") + , @ApiResponse(responseCode = "400" + , description = "M1, 해당 이동봉사 중개를 찾을 수 없습니다." + , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @GetMapping("/intermediaries/notification/setting") + public ResponseEntity getNotification(@AuthenticationPrincipal UserDetails loginUser) { + IntermediaryGetNotificationResponse response = intermediaryService.getNotification(loginUser.getUsername()); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/intermediary/dto/response/IntermediaryGetNotificationResponse.java b/src/main/java/com/pawwithu/connectdog/domain/intermediary/dto/response/IntermediaryGetNotificationResponse.java new file mode 100644 index 00000000..c160bdbb --- /dev/null +++ b/src/main/java/com/pawwithu/connectdog/domain/intermediary/dto/response/IntermediaryGetNotificationResponse.java @@ -0,0 +1,8 @@ +package com.pawwithu.connectdog.domain.intermediary.dto.response; + +public record IntermediaryGetNotificationResponse(Boolean notification) { + + public static IntermediaryGetNotificationResponse of(Boolean notification) { + return new IntermediaryGetNotificationResponse(notification); + } +} diff --git a/src/main/java/com/pawwithu/connectdog/domain/intermediary/entity/Intermediary.java b/src/main/java/com/pawwithu/connectdog/domain/intermediary/entity/Intermediary.java index bbee08b1..667375aa 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/intermediary/entity/Intermediary.java +++ b/src/main/java/com/pawwithu/connectdog/domain/intermediary/entity/Intermediary.java @@ -73,4 +73,6 @@ public void updateProfileWithoutImage(String url, String intro, String contact, public void updatePassword(String password) { this.password = password; } + + public void updateNotification() { this.notification = !this.notification; } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java b/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java index db5d77ac..2008a550 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java @@ -154,4 +154,16 @@ public void changePassword(String email, String password) { intermediary.updatePassword(password); intermediary.passwordEncode(passwordEncoder); } + + public void changeNotification(String email) { + Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); + intermediary.updateNotification(); + } + + @Transactional(readOnly = true) + public IntermediaryGetNotificationResponse getNotification(String email) { + Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); + IntermediaryGetNotificationResponse response = IntermediaryGetNotificationResponse.of(intermediary.getNotification()); + return response; + } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java index ecb413fa..df7be637 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java @@ -126,4 +126,27 @@ public ResponseEntity changePassword(@AuthenticationPrincipal UserDetails return ResponseEntity.noContent().build(); } + @Operation(summary = "설정 - 이동봉사자 알림 설정", description = "이동봉사자 알림을 설정합니다.", + responses = {@ApiResponse(responseCode = "204", description = "이동봉사자 알림 설정 성공") + , @ApiResponse(responseCode = "400" + , description = "M1, 해당 이동봉사자를 찾을 수 없습니다." + , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @PatchMapping("/notification/setting") + public ResponseEntity changeNotification(@AuthenticationPrincipal UserDetails loginUser) { + volunteerService.changeNotification(loginUser.getUsername()); + return ResponseEntity.noContent().build(); + } + + @Operation(summary = "설정 - 이동봉사자 알림 설정 조회", description = "이동봉사자 알림 설정을 조회합니다.", + responses = {@ApiResponse(responseCode = "204", description = "이동봉사자 알림 설정 조회 성공") + , @ApiResponse(responseCode = "400" + , description = "M1, 해당 이동봉사자를 찾을 수 없습니다." + , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @GetMapping("/notification/setting") + public ResponseEntity getNotification(@AuthenticationPrincipal UserDetails loginUser) { + VolunteerGetNotificationResponse response = volunteerService.getNotification(loginUser.getUsername()); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetNotificationResponse.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetNotificationResponse.java new file mode 100644 index 00000000..779572e7 --- /dev/null +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetNotificationResponse.java @@ -0,0 +1,8 @@ +package com.pawwithu.connectdog.domain.volunteer.dto.response; + +public record VolunteerGetNotificationResponse(Boolean notification) { + + public static VolunteerGetNotificationResponse of(Boolean notification) { + return new VolunteerGetNotificationResponse(notification); + } +} diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/entity/Volunteer.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/entity/Volunteer.java index accbfe08..76ac1965 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/volunteer/entity/Volunteer.java +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/entity/Volunteer.java @@ -80,4 +80,6 @@ public void updateProfileImage(Integer profileImageNum) { public void updatePassword(String password) { this.password = password; } + + public void updateNotification() { this.notification = !this.notification; } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java index 68b923cb..978527a0 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java @@ -124,4 +124,16 @@ public void changePassword(String email, String password) { volunteer.updatePassword(password); volunteer.passwordEncode(passwordEncoder); } + + public void changeNotification(String email) { + Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); + volunteer.updateNotification(); + } + + @Transactional(readOnly = true) + public VolunteerGetNotificationResponse getNotification(String email) { + Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); + VolunteerGetNotificationResponse response = VolunteerGetNotificationResponse.of(volunteer.getNotification()); + return response; + } } diff --git a/src/main/resources/import.sql b/src/main/resources/import.sql index cb483e8a..493a214d 100644 --- a/src/main/resources/import.sql +++ b/src/main/resources/import.sql @@ -1,15 +1,15 @@ -- INSERT INTERMEDIARY -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, phone, created_date, modified_date) VALUES (1, 'abc1@naver.com', '{bcrypt}$2a$10$Llg2MwZS/oOv/2/ozaice.49CU35kK6W9kYEb.oqyTy6vmh7E4yv2', '이동봉사 중개', 'https://connectdog.site', 'authImageUrl', 'profileImageUrl', '안녕하세요.', '인스타그램: @hoxjeong', 'AUTH_INTERMEDIARY', false, false, '01012340000', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, phone, created_date, modified_date) VALUES (1, 'abc1@naver.com', '{bcrypt}$2a$10$Llg2MwZS/oOv/2/ozaice.49CU35kK6W9kYEb.oqyTy6vmh7E4yv2', '이동봉사 중개', 'https://connectdog.site', 'authImageUrl', 'profileImageUrl', '안녕하세요.', '인스타그램: @hoxjeong', 'AUTH_INTERMEDIARY', false, true, '01012340000', now(), now()); -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (2, 'i2@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '천사들의 구름쉼터', 'https://connectdog2.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary2.png', '50마리의 아이들이 지내고 있는 천사들의 구름쉼터입니다 :)', '인스타그램 @angel_cloud\n카카오톡 angelcloud02', 'AUTH_INTERMEDIARY', false, false, '안녕하세요~ 천사들의 구름쉼터 입니다. 저희는 따뜻한 봉사자들과 함께 운영하는 봉사단체로 연락이 조금 느릴 수 있지만 최대한 바로 봉사 관련 문의를 전달드리겠습니다 :)', '01012340001', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (2, 'i2@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '천사들의 구름쉼터', 'https://connectdog2.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary2.png', '50마리의 아이들이 지내고 있는 천사들의 구름쉼터입니다 :)', '인스타그램 @angel_cloud\n카카오톡 angelcloud02', 'AUTH_INTERMEDIARY', false, true, '안녕하세요~ 천사들의 구름쉼터 입니다. 저희는 따뜻한 봉사자들과 함께 운영하는 봉사단체로 연락이 조금 느릴 수 있지만 최대한 바로 봉사 관련 문의를 전달드리겠습니다 :)', '01012340001', now(), now()); -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (3, 'i3@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '생명사랑', 'https://connectdog3.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary3.png', '[사단법인] 생명사랑, 후원 환영', '인스타그램 @lovelifehappy', 'AUTH_INTERMEDIARY', false, false, '인스타그램 DM으로만 문의 받습니다.\n보호소 봉사의 경우 네이버 카페 생명사랑에서 신청해 주세요:)', '01012340002', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (3, 'i3@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '생명사랑', 'https://connectdog3.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary3.png', '[사단법인] 생명사랑, 후원 환영', '인스타그램 @lovelifehappy', 'AUTH_INTERMEDIARY', false, true, '인스타그램 DM으로만 문의 받습니다.\n보호소 봉사의 경우 네이버 카페 생명사랑에서 신청해 주세요:)', '01012340002', now(), now()); -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (4, 'i4@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '아지네 보호소', 'https://connectdog4.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary1.png', '강원도에 위치한 작은 보호소 입니다:)', '카카오톡 ajianimalprotect', 'AUTH_INTERMEDIARY', false, false, '초보 봉사자분들도 환영입니다:) 아이들의 이동을 도와주세요.', '01012340003', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (4, 'i4@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '아지네 보호소', 'https://connectdog4.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary1.png', '강원도에 위치한 작은 보호소 입니다:)', '카카오톡 ajianimalprotect', 'AUTH_INTERMEDIARY', false, true, '초보 봉사자분들도 환영입니다:) 아이들의 이동을 도와주세요.', '01012340003', now(), now()); -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (5, 'i5@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '프리독멍멍', 'https://connectdog5.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary4.png', '이동봉사를 전문적으로 진행하는 개인, 프리독멍멍입니다.', '인스타그램 @freedog__\n이메일 freedog2008@naver.com', 'AUTH_INTERMEDIARY', false, false, '❗봉사자 필독사항❗\n1. 대형견의 경우 SUV 차량 보유자만 신청해 주시기 바랍니다.\n2. 아이들 절대로 켄넬에서 꺼내지 말아주세요. 만약 문제 발생 시 저에게 바로 전화주세요.\n3. 신중하게 신청해주세요. 봉사 취소시, 아이들에게 엄청나게 큰 피해가 갑니다ㅠㅠ 제발 부탁드려요', '01012340004', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (5, 'i5@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '프리독멍멍', 'https://connectdog5.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary4.png', '이동봉사를 전문적으로 진행하는 개인, 프리독멍멍입니다.', '인스타그램 @freedog__\n이메일 freedog2008@naver.com', 'AUTH_INTERMEDIARY', false, true, '❗봉사자 필독사항❗\n1. 대형견의 경우 SUV 차량 보유자만 신청해 주시기 바랍니다.\n2. 아이들 절대로 켄넬에서 꺼내지 말아주세요. 만약 문제 발생 시 저에게 바로 전화주세요.\n3. 신중하게 신청해주세요. 봉사 취소시, 아이들에게 엄청나게 큰 피해가 갑니다ㅠㅠ 제발 부탁드려요', '01012340004', now(), now()); -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (6, 'i6@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '천사들의 발자국', 'https://connectdog6.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary5.png', '아이들의 한 발자국에 최선을', '전화 010-4739-1908', 'AUTH_INTERMEDIARY', false, false, 'AM 10:00 ~ PM 8:00 에만 연락해 주세요\n보호소 사정상 연락 바로 못 볼 수도 있습니다.', '01012340005', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, phone, created_date, modified_date) VALUES (6, 'i6@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '천사들의 발자국', 'https://connectdog6.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary5.png', '아이들의 한 발자국에 최선을', '전화 010-4739-1908', 'AUTH_INTERMEDIARY', false, true, 'AM 10:00 ~ PM 8:00 에만 연락해 주세요\n보호소 사정상 연락 바로 못 볼 수도 있습니다.', '01012340005', now(), now()); -- INSERT DOG (post status 0 - 모집중) @@ -111,9 +111,9 @@ UPDATE post SET main_image_id = 15 WHERE id = 15; UPDATE post SET main_image_id = 16 WHERE id = 16; -- INSERT VOLUNTEER -INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (1, 'abc@naver.com', '{bcrypt}$2a$10$VieltvcRaI/rJnaRHuRPju9rqM9BvmKRkmn./oOninx7fOGT/q2De', '이동봉사자', 2, '한호정', '01047391901', 'AUTH_VOLUNTEER', false, false, now(), now()); +INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (1, 'abc@naver.com', '{bcrypt}$2a$10$VieltvcRaI/rJnaRHuRPju9rqM9BvmKRkmn./oOninx7fOGT/q2De', '이동봉사자', 2, '한호정', '01047391901', 'AUTH_VOLUNTEER', false, true, now(), now()); -INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (2, 'v1@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '하얀마음', 1, '민경혁', '01047391902', 'AUTH_VOLUNTEER', false, false, now(), now()); +INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (2, 'v1@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '하얀마음', 1, '민경혁', '01047391902', 'AUTH_VOLUNTEER', false, true, now(), now()); -- INSERT APPLICATION (status 2 - 봉사완료) @@ -223,7 +223,7 @@ INSERT INTO bookmark(id, post_id, volunteer_id, created_date, modified_date) VAL -- v2 -- INSERT INTERMEDIARY -INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, created_date, modified_date) VALUES (7, 'i7@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '감귤시보호소', 'https://connectdog7.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary6.png','감귤시가 운영중인 유기견 보호소입니다', '인스타그램 @gamgull_helper', 'AUTH_INTERMEDIARY', false, false, '감귤시에서 운영하는 감귤시보호소 공식계정입니다. 직원들이 상주하는 평일 9:00~19:0에만 응답이 가능합니다. ', now(), now()); +INSERT INTO intermediary (id, email, password, name, url, auth_image, profile_image, intro, contact, role, is_option_agr, notification, guide, created_date, modified_date) VALUES (7, 'i7@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '감귤시보호소', 'https://connectdog7.site', 'authImageUrl', 'https://connectdog-image.s3.ap-northeast-2.amazonaws.com/intermediary/intermediary6.png','감귤시가 운영중인 유기견 보호소입니다', '인스타그램 @gamgull_helper', 'AUTH_INTERMEDIARY', false, true, '감귤시에서 운영하는 감귤시보호소 공식계정입니다. 직원들이 상주하는 평일 9:00~19:0에만 응답이 가능합니다. ', now(), now()); -- INSERT DOG (post status 0 - 모집중) @@ -385,10 +385,10 @@ UPDATE post SET main_image_id = 44 WHERE id = 44; -- INSERT VOLUNTEER -INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (3, 'v2@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '포포사랑', 3, '이시윤', '01047391903', 'AUTH_VOLUNTEER', false, false, now(), now()); -INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (4, 'v3@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '하늘천사', 4, '권예인', '01047391904', 'AUTH_VOLUNTEER', false, false, now(), now()); -INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (5, 'v4@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '코코엄마', 5, '강승구', '01047391905', 'AUTH_VOLUNTEER', false, false, now(), now()); -INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (6, 'v5@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '산책가자', 6, '김민주', '01047391906', 'AUTH_VOLUNTEER', false, false, now(), now()); +INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (3, 'v2@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '포포사랑', 3, '이시윤', '01047391903', 'AUTH_VOLUNTEER', false, true, now(), now()); +INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (4, 'v3@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '하늘천사', 4, '권예인', '01047391904', 'AUTH_VOLUNTEER', false, true, now(), now()); +INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (5, 'v4@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '코코엄마', 5, '강승구', '01047391905', 'AUTH_VOLUNTEER', false, true, now(), now()); +INSERT INTO volunteer (id, email, password, nickname, profile_image_num, name, phone, role, is_option_agr, notification, created_date, modified_date) VALUES (6, 'v5@naver.com', '{bcrypt}$2a$10$wkmYUG/qvZFThCzq19yHredRc6u8nAhlAopbDE9p7n6JF6NgtLs8y', '산책가자', 6, '김민주', '01047391906', 'AUTH_VOLUNTEER', false, true, now(), now()); -- INSERT APPLICATION (status 0 - 승인대기중) diff --git a/src/test/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryControllerTest.java b/src/test/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryControllerTest.java index ffa5e67b..2da50e55 100644 --- a/src/test/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryControllerTest.java +++ b/src/test/java/com/pawwithu/connectdog/domain/intermediary/controller/IntermediaryControllerTest.java @@ -302,4 +302,33 @@ void setUp() { verify(intermediaryService, times(1)).changePassword(anyString(), any()); } + + @Test + void 모집자_알림_설정() throws Exception { + // given, when + ResultActions result = mockMvc.perform( + patch("/intermediaries/notification/setting") + ); + + // then + result.andExpect(status().isNoContent()); + verify(intermediaryService, times(1)).changeNotification(anyString()); + } + + @Test + void 모집자_알림_설정_조회() throws Exception { + // given + IntermediaryGetNotificationResponse request = new IntermediaryGetNotificationResponse(false); + + // when + ResultActions result = mockMvc.perform( + get("/intermediaries/notification/setting") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + + // then + result.andExpect(status().isOk()); + verify(intermediaryService, times(1)).getNotification(anyString()); + } } \ No newline at end of file diff --git a/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java b/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java index c14bef57..97ee91b5 100644 --- a/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java +++ b/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java @@ -195,6 +195,34 @@ void setUp() { // then result.andExpect(status().isNoContent()); verify(volunteerService, times(1)).changePassword(anyString(), any()); + } + + @Test + void 이동봉사자_알림_설정() throws Exception { + // given, when + ResultActions result = mockMvc.perform( + patch("/volunteers/notification/setting") + ); + + // then + result.andExpect(status().isNoContent()); + verify(volunteerService, times(1)).changeNotification(anyString()); + } + + @Test + void 이동봉사자_알림_설정_조회() throws Exception { + // given + VolunteerGetNotificationResponse request = new VolunteerGetNotificationResponse(false); + + // when + ResultActions result = mockMvc.perform( + get("/volunteers/notification/setting") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ); + // then + result.andExpect(status().isOk()); + verify(volunteerService, times(1)).getNotification(anyString()); } } \ No newline at end of file