From c895a0b1b6ebe6be9d63dab747c9f4ff72547378 Mon Sep 17 00:00:00 2001 From: hyeonjeongs Date: Wed, 28 Feb 2024 09:50:45 +0900 Subject: [PATCH] =?UTF-8?q?YEL-214=20[feat]=20=ED=88=AC=ED=91=9C=20?= =?UTF-8?q?=EC=97=B4=EB=9E=8C=EC=8B=9C=20=EB=B3=B4=EB=82=B8=EC=82=AC?= =?UTF-8?q?=EB=9E=8C=EC=97=90=EA=B2=8C=20=ED=91=B8=EC=8B=9C=EC=95=8C?= =?UTF-8?q?=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/vote/service/VoteService.java | 6 ++++++ .../firebase/dto/NotificationType.java | 3 ++- .../firebase/dto/request/NotificationMessage.java | 8 ++++++++ .../firebase/service/NotificationFcmService.java | 12 ++++++++++++ .../firebase/service/NotificationService.java | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yello/server/domain/vote/service/VoteService.java b/src/main/java/com/yello/server/domain/vote/service/VoteService.java index 7c23eb3b..246aef58 100644 --- a/src/main/java/com/yello/server/domain/vote/service/VoteService.java +++ b/src/main/java/com/yello/server/domain/vote/service/VoteService.java @@ -45,6 +45,7 @@ import com.yello.server.domain.vote.exception.VoteForbiddenException; import com.yello.server.domain.vote.exception.VoteNotFoundException; import com.yello.server.domain.vote.repository.VoteRepository; +import com.yello.server.infrastructure.firebase.service.NotificationService; import com.yello.server.infrastructure.rabbitmq.service.ProducerService; import java.time.LocalDateTime; import java.util.List; @@ -73,6 +74,7 @@ public class VoteService { private final VoteManager voteManager; private final ProducerService producerService; + private final NotificationService notificationService; public VoteListResponse findAllVotes(Long userId, Pageable pageable) { Integer totalCount = voteRepository.countAllByReceiverUserId(userId); @@ -104,6 +106,10 @@ public VoteDetailResponse findVoteById(Long voteId, Long userId) { final Vote vote = voteRepository.getById(voteId); final User user = userRepository.getById(userId); + if(!vote.getIsRead()) { + notificationService.sendOpenVoteNotification(user); + } + vote.read(); return VoteDetailResponse.of(vote, user); } diff --git a/src/main/java/com/yello/server/infrastructure/firebase/dto/NotificationType.java b/src/main/java/com/yello/server/infrastructure/firebase/dto/NotificationType.java index f940b3bd..6ab4a915 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/dto/NotificationType.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/dto/NotificationType.java @@ -5,5 +5,6 @@ public enum NotificationType { VOTE_AVAILABLE, NEW_FRIEND, RECOMMEND, - LUNCH_EVENT + LUNCH_EVENT, + OPEN_VOTE } diff --git a/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java b/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java index 430e60a0..baa9063d 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.java @@ -52,6 +52,14 @@ public static NotificationMessage toYelloNotificationContent(Vote vote) { .build(); } + public static NotificationMessage toUserOpenVoteNotificationContent(User user) { + return NotificationMessage.builder() + .title(MessageFormat.format("{0}님이 내가 보낸 쪽지를 확인했어요! ", user.getName())) + .message("\uD83D\uDEA8\uD83D\uDC9A 그린라이트입니다.") + .type(NotificationType.OPEN_VOTE) + .build(); + } + public static NotificationMessage toAllUserLunchEventNotificationContent() { return NotificationMessage.builder() .title("우리 학교 선착순 30명 열람권 뿌린다!") diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java index c4d1a6cc..9295d2de 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java @@ -133,4 +133,16 @@ public void sendLunchEventNotification(User user) { } } + + @Override + public void sendOpenVoteNotification(User user) { + NotificationMessage notificationMessage = + NotificationMessage.toUserOpenVoteNotificationContent(user); + + if (user.getDeviceToken() != null && !Objects.equals(user.getDeviceToken(), "")) { + final Message message = + fcmManager.createMessage(user.getDeviceToken(), notificationMessage); + fcmManager.send(message); + } + } } diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java index 0ebd7cc2..040c2889 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java @@ -22,4 +22,6 @@ public interface NotificationService { EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomMessage request); void sendLunchEventNotification(User userList); + + void sendOpenVoteNotification(User user); }