diff --git a/src/main/java/com/ceos/bankids/controller/NotificationController.java b/src/main/java/com/ceos/bankids/controller/NotificationController.java index d196e21e..847f4e35 100644 --- a/src/main/java/com/ceos/bankids/controller/NotificationController.java +++ b/src/main/java/com/ceos/bankids/controller/NotificationController.java @@ -65,10 +65,11 @@ public CommonResponse allSendNotification( .forEach(user -> { if (user.getNoticeOptIn()) { expoNotificationService.sendMessage(user, title, message, - allSendNotificationRequest.getNewMap(), notificationCategory); + allSendNotificationRequest.getNewMap(), notificationCategory, "/"); } else { Notification notification = Notification.builder().user(user).title(title) - .message(message).notificationCategory(notificationCategory).build(); + .message(message).notificationCategory(notificationCategory).linkUrl("/") + .build(); notificationRepository.save(notification); } }); @@ -126,10 +127,10 @@ public void notification(Challenge challenge, User authUser) { newMap.put("userId", authUser.getId()); NotificationCategory notificationCategory = NotificationCategory.CHALLENGE; Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody, - notificationCategory); + notificationCategory, "/"); if (checkServiceOptIn) { expoNotificationService.sendMessage(authUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, "/"); } log.info("유저 {}의 돈길 {}의 {} 상태변경 알림", authUser.getId(), challenge.getId(), challenge.getChallengeStatus()); @@ -145,10 +146,10 @@ public void userLevelUpMinusOne(User authUser) { newMap.put("userId", authUser.getId()); NotificationCategory notificationCategory = NotificationCategory.LEVEL; Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody, - notificationCategory); + notificationCategory, "/mypage"); if (checkServiceOptIn) { expoNotificationService.sendMessage(authUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, "/mypage"); } log.info("유저 id = {}의 레벨업 직전 알림", authUser.getId()); } @@ -164,10 +165,10 @@ public void userLevelUpHalf(User authUser) { newMap.put("userId", authUser.getId()); NotificationCategory notificationCategory = NotificationCategory.LEVEL; Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody, - notificationCategory); + notificationCategory, "/mypage"); if (checkServiceOptIn) { expoNotificationService.sendMessage(authUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, "/mypage"); } log.info("유저 id = {}의 레벨업 절반 달성 알림", authUser.getId()); } @@ -184,10 +185,10 @@ public void createPendingChallengeNotification(User contractUser, ChallengeUser newMap.put("challenge", challengeUser.getChallenge().getId()); NotificationCategory notificationCategory = NotificationCategory.CHALLENGE; Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody, - notificationCategory); + notificationCategory, ""); if (checkServiceOptIn) { expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, ""); } log.info("부모 유저 id = {}에게 유저 id = {} 돈길 id = {} 의 돈길 제안", contractUser.getId(), challengeUser.getUser().getId(), challengeUser.getChallenge().getId()); @@ -205,10 +206,10 @@ public void runProgressNotification(User contractUser, ChallengeUser challengeUs newMap.put("challenge", challengeUser.getChallenge().getId()); NotificationCategory notificationCategory = NotificationCategory.CHALLENGE; Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody, - notificationCategory); + notificationCategory, "/"); if (checkServiceOptIn) { expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, "/"); } log.info("부모 유저 id = {}에게 유저 id = {}의 돈길 id = {} 돈길 걷기 알림 전송", contractUser.getId(), challengeUser.getUser().getId(), challengeUser.getChallenge().getId()); @@ -227,10 +228,10 @@ public void achieveChallengeNotification(User contractUser, ChallengeUser challe newMap.put("challenge", challengeUser.getChallenge().getId()); NotificationCategory notificationCategory = NotificationCategory.CHALLENGE; Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody, - notificationCategory); + notificationCategory, "/"); if (checkServiceOptIn) { expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, "/"); } log.info("부모 유저 id = {}에게 유저 id = {}의 돈길 id = {} 돈길 완주 알림 전송", contractUser.getId(), challengeUser.getUser().getId(), challengeUser.getChallenge().getId()); @@ -247,10 +248,10 @@ public void kidLevelUpNotification(User contractUser, User user, Long level, Lon newMap.put("user", user.getId()); NotificationCategory notificationCategory = NotificationCategory.LEVEL; Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody, - notificationCategory); + notificationCategory, ""); if (checkServiceOptIn) { expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, ""); } log.info("부모 유저 id = {}에게 유저 id = {}의 레벨업 알림 전송", contractUser.getId(), user.getId()); } @@ -266,10 +267,10 @@ public void challengeFailedNotification(User contractUser, ChallengeUser challen newMap.put("challenge", challengeUser.getChallenge().getId()); NotificationCategory notificationCategory = NotificationCategory.CHALLENGE; Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody, - notificationCategory); + notificationCategory, "/"); if (checkServiceOptIn) { expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap, - notificationCategory); + notificationCategory, "/"); } log.info("부모 유저 id = {}에게 유저 id = {}의 돈길 id = {} 돈길 실패 알림 전송", contractUser.getId(), challengeUser.getChallenge().getId(), challengeUser.getChallenge().getId()); @@ -286,10 +287,10 @@ public void newFamilyUserNotification(User newFamilyUser, List famil familyUserList.forEach(familyUser -> { User user = familyUser.getUser(); Boolean checkServiceOptIn = checkServiceOptIn(user, title, notificationBody, - notificationCategory); + notificationCategory, ""); if (checkServiceOptIn) { expoNotificationService.sendMessage(user, title, notificationBody, newMap, - notificationCategory); + notificationCategory, ""); } log.info("기존 가족 구성원 id = {}에게 유저 id = {}의 가족 참여 알림 전송", familyUser.getUser().getId(), newFamilyUser.getId()); @@ -297,10 +298,10 @@ public void newFamilyUserNotification(User newFamilyUser, List famil } private Boolean checkServiceOptIn(User user, String title, String body, - NotificationCategory notificationCategory) { + NotificationCategory notificationCategory, String linkUrl) { if (!user.getServiceOptIn()) { Notification notification = Notification.builder().user(user).title(title).message(body) - .notificationCategory(notificationCategory) + .notificationCategory(notificationCategory).linkUrl(linkUrl) .build(); notificationRepository.save(notification); return false; diff --git a/src/main/java/com/ceos/bankids/domain/Notification.java b/src/main/java/com/ceos/bankids/domain/Notification.java index d2e437e5..313a33b6 100644 --- a/src/main/java/com/ceos/bankids/domain/Notification.java +++ b/src/main/java/com/ceos/bankids/domain/Notification.java @@ -47,6 +47,9 @@ public class Notification extends AbstractTimestamp { @Enumerated(EnumType.STRING) private NotificationCategory notificationCategory; + @Column(nullable = false) + private String linkUrl; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId", nullable = false) private User user; @@ -58,6 +61,7 @@ public Notification( String message, Boolean isRead, NotificationCategory notificationCategory, + String linkUrl, User user ) { @@ -66,6 +70,7 @@ public Notification( this.message = message; this.isRead = isRead; this.notificationCategory = notificationCategory; + this.linkUrl = linkUrl; this.user = user; } } diff --git a/src/main/java/com/ceos/bankids/dto/NotificationDTO.java b/src/main/java/com/ceos/bankids/dto/NotificationDTO.java index 41be840e..31c3c177 100644 --- a/src/main/java/com/ceos/bankids/dto/NotificationDTO.java +++ b/src/main/java/com/ceos/bankids/dto/NotificationDTO.java @@ -31,6 +31,9 @@ public class NotificationDTO { @ApiModelProperty(example = "CHALLENGE") private NotificationCategory notificationCategory; + @ApiModelProperty(example = "/") + private String linkUrl; + @ApiModelProperty(example = "2022/07/05 05:05:05") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy/MM/dd hh:mm:ss", timezone = "Asia/Seoul") private Timestamp createdAt; @@ -41,6 +44,7 @@ public NotificationDTO(Notification notification) { this.message = notification.getMessage(); this.isRead = notification.getIsRead(); this.notificationCategory = notification.getNotificationCategory(); + this.linkUrl = notification.getLinkUrl(); this.createdAt = notification.getCreatedAt(); } } diff --git a/src/main/java/com/ceos/bankids/service/ExpoNotificationServiceImpl.java b/src/main/java/com/ceos/bankids/service/ExpoNotificationServiceImpl.java index f4a6897a..d26a9d83 100644 --- a/src/main/java/com/ceos/bankids/service/ExpoNotificationServiceImpl.java +++ b/src/main/java/com/ceos/bankids/service/ExpoNotificationServiceImpl.java @@ -111,7 +111,7 @@ public void deleteAllNotification(User user) { } public void sendMessage(User user, String title, String body, Map data, - NotificationCategory notificationCategory) { + NotificationCategory notificationCategory, String linkUrl) { String token = user.getExpoToken(); if (token == null) { @@ -143,7 +143,7 @@ public void sendMessage(User user, String title, String body, Map allTickets = new ArrayList<>(); for (CompletableFuture> messageReplyFuture : messageRepliesFutures) {