From e979c578f8e1c062b99681e06a670555820556f2 Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Wed, 15 May 2024 12:49:17 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EB=B4=89=EC=82=AC=EC=9E=90=20?= =?UTF-8?q?=EB=AA=A8=EC=A7=91=EC=9E=90=20=EC=95=8C=EB=A6=BC=20Entity?= =?UTF-8?q?=EC=97=90=20NotificationType=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/IntermediaryNotification.java | 18 +++++++++++------- .../notification/entity/NotificationType.java | 17 +++++++++++++++++ .../entity/VolunteerNotification.java | 6 +++++- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/pawwithu/connectdog/domain/notification/entity/NotificationType.java diff --git a/src/main/java/com/pawwithu/connectdog/domain/notification/entity/IntermediaryNotification.java b/src/main/java/com/pawwithu/connectdog/domain/notification/entity/IntermediaryNotification.java index a1b4cf35..7279beea 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/notification/entity/IntermediaryNotification.java +++ b/src/main/java/com/pawwithu/connectdog/domain/notification/entity/IntermediaryNotification.java @@ -15,6 +15,9 @@ public class IntermediaryNotification extends BaseTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String image; + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private NotificationType notificationType; @Column(nullable = false) private String title; @Column(nullable = false) @@ -26,11 +29,12 @@ public class IntermediaryNotification extends BaseTimeEntity { private Boolean isRead; @Builder - public IntermediaryNotification(String image, String title, String body, Intermediary intermediary, Boolean isRead) { - this.image = image; - this.title = title; - this.body = body; - this.intermediary = intermediary; - this.isRead = isRead; - } + public IntermediaryNotification(String image, NotificationType notificationType, String title, String body, Intermediary intermediary, Boolean isRead) { + this.image = image; + this.notificationType = notificationType; + this.title = title; + this.body = body; + this.intermediary = intermediary; + this.isRead = isRead; } +} diff --git a/src/main/java/com/pawwithu/connectdog/domain/notification/entity/NotificationType.java b/src/main/java/com/pawwithu/connectdog/domain/notification/entity/NotificationType.java new file mode 100644 index 00000000..553f68ac --- /dev/null +++ b/src/main/java/com/pawwithu/connectdog/domain/notification/entity/NotificationType.java @@ -0,0 +1,17 @@ +package com.pawwithu.connectdog.domain.notification.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum NotificationType { + + // 봉사자 + REJECTED("반려 확인"), CONFIRMED("승인 확인"), COMPLETED("봉사 완료"), BADGE("배지 확득"), + + // 모집자 + APPLICATION("신청 확인"), CANCELED("봉사 취소"), REVIEW_REGISTERED("후기 확인"), EXPIRED("모집 마감"), COMPLETED_REQUEST("봉사 완료 요청"); + + private final String key; +} diff --git a/src/main/java/com/pawwithu/connectdog/domain/notification/entity/VolunteerNotification.java b/src/main/java/com/pawwithu/connectdog/domain/notification/entity/VolunteerNotification.java index ed24ca18..23e931dd 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/notification/entity/VolunteerNotification.java +++ b/src/main/java/com/pawwithu/connectdog/domain/notification/entity/VolunteerNotification.java @@ -15,6 +15,9 @@ public class VolunteerNotification extends BaseTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String image; + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private NotificationType notificationType; @Column(nullable = false) private String title; @Column(nullable = false) @@ -26,8 +29,9 @@ public class VolunteerNotification extends BaseTimeEntity { private Boolean isRead; @Builder - public VolunteerNotification(String image, String title, String body, Volunteer volunteer, Boolean isRead) { + public VolunteerNotification(String image, NotificationType notificationType, String title, String body, Volunteer volunteer, Boolean isRead) { this.image = image; + this.notificationType = notificationType; this.title = title; this.body = body; this.volunteer = volunteer; From a99db4f60a03131eafc7e95323f1ab89503b1f67 Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Wed, 15 May 2024 12:52:16 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=97=90=20NotificationType=20=EC=B6=94=EA=B0=80=20(#?= =?UTF-8?q?193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/ApplicationService.java | 16 +++++++++++----- .../domain/fcm/controller/FcmController.java | 3 ++- .../domain/fcm/service/FcmService.java | 9 +++++++-- .../domain/review/service/ReviewService.java | 4 +++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java b/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java index 5943b99e..6af9154e 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java @@ -13,6 +13,7 @@ import com.pawwithu.connectdog.domain.fcm.service.FcmService; import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary; import com.pawwithu.connectdog.domain.intermediary.repository.IntermediaryRepository; +import com.pawwithu.connectdog.domain.notification.entity.NotificationType; import com.pawwithu.connectdog.domain.post.entity.Post; import com.pawwithu.connectdog.domain.post.entity.PostStatus; import com.pawwithu.connectdog.domain.post.repository.PostRepository; @@ -64,7 +65,8 @@ public void volunteerApply(String email, Long postId, VolunteerApplyRequest requ // 알림 전송 IntermediaryFcm intermediaryFcm = intermediaryFcmRepository.findByIntermediaryId(intermediary.getId()).orElse(null); if (intermediaryFcm != null) { - fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), intermediary, volunteer.getProfileImageNum() + "", APPLICATION.getTitle(), APPLICATION.getBodyWithName(volunteer.getNickname())); + fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), intermediary, volunteer.getProfileImageNum() + "", + NotificationType.APPLICATION, APPLICATION.getTitle(), APPLICATION.getBodyWithName(volunteer.getNickname())); } else { log.info("----------이동봉사 신청 알림 전송 실패----------"); } @@ -108,7 +110,8 @@ public ApplicationSuccessResponse deleteApplication(String email, Long applicati // 알림 전송 IntermediaryFcm intermediaryFcm = intermediaryFcmRepository.findByIntermediaryId(application.getIntermediary().getId()).orElse(null); if (intermediaryFcm != null) { - fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), application.getIntermediary(), volunteer.getProfileImageNum() + "", CANCELED.getTitle(), CANCELED.getBodyWithName(volunteer.getNickname())); + fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), application.getIntermediary(), volunteer.getProfileImageNum() + "", + NotificationType.CANCELED, CANCELED.getTitle(), CANCELED.getBodyWithName(volunteer.getNickname())); } else { log.info("----------이동봉사 신청 취소 알림 전송 실패----------"); } @@ -128,7 +131,8 @@ public ApplicationSuccessResponse confirmApplication(String email, Long applicat // 알림 전송 VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(application.getVolunteer().getId()).orElse(null); if (volunteerFcm != null) { - fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), CONFIRM.getTitle(), CONFIRM.getBody()); + fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), + NotificationType.CONFIRMED, CONFIRM.getTitle(), CONFIRM.getBody()); } else { log.info("----------이동봉사 승인 알림 전송 실패----------"); } @@ -148,7 +152,8 @@ public ApplicationSuccessResponse cancelApplication(String email, Long applicati // 알림 전송 VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(application.getVolunteer().getId()).orElse(null); if (volunteerFcm != null) { - fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), REJECT.getTitle(), REJECT.getBody()); + fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), + NotificationType.REJECTED, REJECT.getTitle(), REJECT.getBody()); } else { log.info("----------이동봉사 반려 알림 전송 실패----------"); } @@ -218,7 +223,8 @@ public ApplicationSuccessResponse completeApplication(String email, Long applica // 알림 전송 VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(application.getVolunteer().getId()).orElse(null); if (volunteerFcm != null) { - fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), COMPLETED.getTitle(), COMPLETED.getBody()); + fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), + NotificationType.COMPLETED, COMPLETED.getTitle(), COMPLETED.getBody()); } else { log.info("----------이동봉사 완료 알림 전송 실패----------"); } diff --git a/src/main/java/com/pawwithu/connectdog/domain/fcm/controller/FcmController.java b/src/main/java/com/pawwithu/connectdog/domain/fcm/controller/FcmController.java index 7626a2bf..3bf58b2f 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/fcm/controller/FcmController.java +++ b/src/main/java/com/pawwithu/connectdog/domain/fcm/controller/FcmController.java @@ -4,6 +4,7 @@ import com.pawwithu.connectdog.domain.fcm.dto.request.IntermediaryFcmRequest; import com.pawwithu.connectdog.domain.fcm.dto.request.VolunteerFcmRequest; import com.pawwithu.connectdog.domain.fcm.service.FcmService; +import com.pawwithu.connectdog.domain.notification.entity.NotificationType; import com.pawwithu.connectdog.error.dto.ErrorResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -64,7 +65,7 @@ public ResponseEntity saveIntermediaryFcm(@AuthenticationPrincipal UserDet }) @PostMapping("/fcm-test") public ResponseEntity testFcmToken(@Valid @RequestBody FcmTokenRequest request) { - fcmService.sendMessageToVolunteer(request.fcmToken(), null, null, APPLICATION.getTitleWithLoc("서울 강남구", "서울 도봉구"), APPLICATION.getBodyWithName("포윗유")); + fcmService.sendMessageToVolunteer(request.fcmToken(), null, null, NotificationType.APPLICATION, APPLICATION.getTitleWithLoc("서울 강남구", "서울 도봉구"), APPLICATION.getBodyWithName("포윗유")); return ResponseEntity.noContent().build(); } 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 bac1ad4f..b0c8393c 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 @@ -14,6 +14,7 @@ import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary; import com.pawwithu.connectdog.domain.intermediary.repository.IntermediaryRepository; import com.pawwithu.connectdog.domain.notification.entity.IntermediaryNotification; +import com.pawwithu.connectdog.domain.notification.entity.NotificationType; import com.pawwithu.connectdog.domain.notification.entity.VolunteerNotification; import com.pawwithu.connectdog.domain.notification.repository.IntermediaryNotificationRepository; import com.pawwithu.connectdog.domain.notification.repository.VolunteerNotificationRepository; @@ -97,7 +98,8 @@ public String makeMessage(String targetToken, String title, String body) throws * 알림 푸쉬를 보내는 역할을 하는 메서드 * @param targetToken : 푸쉬 알림을 받을 클라이언트 앱의 식별 토큰 * */ - public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, String image, String title, String body) { + public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, String image, + NotificationType notificationType, String title, String body) { try { String message = makeMessage(targetToken, title, body); @@ -118,6 +120,7 @@ public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, Stri volunteerNotificationRepository.save( VolunteerNotification.builder() .image(image) + .notificationType(notificationType) .title(title) .body(body) .volunteer(volunteer) @@ -135,7 +138,8 @@ public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, Stri } } - public void sendMessageToIntermediary(String targetToken, Intermediary intermediary, String image, String title, String body) { + public void sendMessageToIntermediary(String targetToken, Intermediary intermediary, String image, + NotificationType notificationType, String title, String body) { try { String message = makeMessage(targetToken, title, body); @@ -156,6 +160,7 @@ public void sendMessageToIntermediary(String targetToken, Intermediary intermedi intermediaryNotificationRepository.save( IntermediaryNotification.builder() .image(image) + .notificationType(notificationType) .title(title) .body(body) .intermediary(intermediary) diff --git a/src/main/java/com/pawwithu/connectdog/domain/review/service/ReviewService.java b/src/main/java/com/pawwithu/connectdog/domain/review/service/ReviewService.java index 3a851e39..01201445 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/review/service/ReviewService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/review/service/ReviewService.java @@ -5,6 +5,7 @@ import com.pawwithu.connectdog.domain.fcm.entity.IntermediaryFcm; import com.pawwithu.connectdog.domain.fcm.repository.IntermediaryFcmRepository; import com.pawwithu.connectdog.domain.fcm.service.FcmService; +import com.pawwithu.connectdog.domain.notification.entity.NotificationType; import com.pawwithu.connectdog.domain.post.entity.Post; import com.pawwithu.connectdog.domain.post.repository.PostRepository; import com.pawwithu.connectdog.domain.review.dto.request.ReviewCreateRequest; @@ -81,7 +82,8 @@ public void createReview(String email, Long postId, ReviewCreateRequest request, // 알림 전송 IntermediaryFcm intermediaryFcm = intermediaryFcmRepository.findByIntermediaryId(post.getIntermediary().getId()).orElse(null); if (intermediaryFcm != null) { - fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), post.getIntermediary(), post.getMainImage().getImage(), REVIEW_REGISTERED.getTitle(), REVIEW_REGISTERED.getBody()); + fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), post.getIntermediary(), post.getMainImage().getImage(), + NotificationType.REVIEW_REGISTERED, REVIEW_REGISTERED.getTitle(), REVIEW_REGISTERED.getBody()); } else { log.info("----------이동봉사 후기 등록 알림 전송 실패----------"); } From 46155b5a56184e9fdf295cb2301c16108b525783 Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Wed, 15 May 2024 12:55:13 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EB=B4=89=EC=82=AC=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C,=20=EB=B0=98=EB=A0=A4=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20(#193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/controller/ApplicationController.java | 10 +++++----- .../domain/application/service/ApplicationService.java | 4 ++-- .../controller/ApplicationControllerTest.java | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java b/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java index 4ad3a853..e2c0a2bd 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java @@ -89,9 +89,9 @@ public ResponseEntity getVolunteerOneApplica , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) @DeleteMapping( "/volunteers/applications/{applicationId}") - public ResponseEntity deleteApplication(@AuthenticationPrincipal UserDetails loginUser, + public ResponseEntity cancelApplication(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long applicationId) { - ApplicationSuccessResponse response = applicationService.deleteApplication(loginUser.getUsername(), applicationId); + ApplicationSuccessResponse response = applicationService.cancelApplication(loginUser.getUsername(), applicationId); return ResponseEntity.ok(response); } @@ -115,9 +115,9 @@ public ResponseEntity confirmApplication(@Authentica , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) @DeleteMapping( "/intermediaries/applications/{applicationId}") - public ResponseEntity cancelApplication(@AuthenticationPrincipal UserDetails loginUser, - @PathVariable Long applicationId) { - ApplicationSuccessResponse response = applicationService.cancelApplication(loginUser.getUsername(), applicationId); + public ResponseEntity rejectApplication(@AuthenticationPrincipal UserDetails loginUser, + @PathVariable Long applicationId) { + ApplicationSuccessResponse response = applicationService.rejectApplication(loginUser.getUsername(), applicationId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java b/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java index 6af9154e..d688c8a7 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java @@ -98,7 +98,7 @@ public ApplicationVolunteerGetOneResponse getVolunteerOneApplication(String emai return oneApplication; } - public ApplicationSuccessResponse deleteApplication(String email, Long applicationId) { + public ApplicationSuccessResponse cancelApplication(String email, Long applicationId) { // 이동봉사자 Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); // 신청 내역 + post @@ -140,7 +140,7 @@ public ApplicationSuccessResponse confirmApplication(String email, Long applicat return isSuccess; } - public ApplicationSuccessResponse cancelApplication(String email, Long applicationId) { + public ApplicationSuccessResponse rejectApplication(String email, Long applicationId) { // 이동봉사 중개 Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); // 신청 내역 + post diff --git a/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java b/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java index ce32e485..43216ebf 100644 --- a/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java +++ b/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java @@ -139,14 +139,14 @@ void setUp() { ApplicationSuccessResponse response = new ApplicationSuccessResponse(true); //when - given(applicationService.deleteApplication(anyString(), anyLong())).willReturn(response); + given(applicationService.cancelApplication(anyString(), anyLong())).willReturn(response); ResultActions result = mockMvc.perform( delete("/volunteers/applications/{applicationId}", applicationId) ); //then result.andExpect(status().isOk()); - verify(applicationService, times(1)).deleteApplication(anyString(), anyLong()); + verify(applicationService, times(1)).cancelApplication(anyString(), anyLong()); } @Test @@ -173,14 +173,14 @@ void setUp() { ApplicationSuccessResponse response = new ApplicationSuccessResponse(true); //when - given(applicationService.cancelApplication(anyString(), anyLong())).willReturn(response); + given(applicationService.rejectApplication(anyString(), anyLong())).willReturn(response); ResultActions result = mockMvc.perform( delete("/intermediaries/applications/{applicationId}", applicationId) ); //then result.andExpect(status().isOk()); - verify(applicationService, times(1)).cancelApplication(anyString(), anyLong()); + verify(applicationService, times(1)).rejectApplication(anyString(), anyLong()); } @Test