diff --git a/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java b/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java index 80a41675..ee7489cd 100644 --- a/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java +++ b/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java @@ -186,11 +186,16 @@ private void sendBoostNotification( .map(FcmToken::getToken) .orElseThrow(() -> new CustomException(ErrorCode.FAILED_TO_FIND_FCM_TOKEN)); + String deepLink = + FcmNotification.generateDeepLink( + FcmNotificationType.BOOSTER, missionRecord.getId()); + FcmMessage fcmMessage = FcmMessage.of( notificationConstants.getTitle(), notificationConstants.getMessage(), - token); + token, + deepLink); sqsMessageService.sendMessage(fcmMessage); saveNotification( @@ -237,8 +242,10 @@ private List buildNotificationList( public void sendAndNotifications(String title, String message, List tokens) { List> batches = createBatches(tokens, 10); + String deepLink = FcmNotification.generateDeepLink(FcmNotificationType.MISSION, null); + for (List batch : batches) { - sqsMessageService.sendBatchMessages(batch, title, message); + sqsMessageService.sendBatchMessages(batch, title, message, deepLink); } List notifications = buildNotificationList(title, message, tokens); diff --git a/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmMessage.java b/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmMessage.java index cfde6096..de791772 100644 --- a/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmMessage.java +++ b/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmMessage.java @@ -1,8 +1,8 @@ package com.depromeet.stonebed.domain.fcm.domain; -public record FcmMessage(String title, String body, String token) { +public record FcmMessage(String title, String body, String token, String deepLink) { - public static FcmMessage of(String title, String body, String token) { - return new FcmMessage(title, body, token); + public static FcmMessage of(String title, String body, String token, String deepLink) { + return new FcmMessage(title, body, token, deepLink); } } diff --git a/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmNotification.java b/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmNotification.java index 1ed1b01e..683e0476 100644 --- a/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmNotification.java +++ b/src/main/java/com/depromeet/stonebed/domain/fcm/domain/FcmNotification.java @@ -39,21 +39,21 @@ public class FcmNotification extends BaseTimeEntity { @Schema(description = "딥링크 URL", example = "myapp://notification/1") private String deepLink; + private static final String DEEP_LINK_PREFIX = "myapp://"; + private FcmNotification( FcmNotificationType type, String title, String message, Member member, Long targetId, - Boolean isRead, - String deepLink) { + Boolean isRead) { this.type = type; this.title = title; this.message = message; this.member = member; this.targetId = targetId; this.isRead = isRead; - this.deepLink = deepLink; } public static FcmNotification create( @@ -63,19 +63,18 @@ public static FcmNotification create( Member member, Long targetId, Boolean isRead) { - String deepLink = generateDeepLink(type, targetId); - return new FcmNotification(type, title, message, member, targetId, isRead, deepLink); + return new FcmNotification(type, title, message, member, targetId, isRead); } public void markAsRead() { this.isRead = true; } - private static String generateDeepLink(FcmNotificationType type, Long targetId) { + public static String generateDeepLink(FcmNotificationType type, Long targetId) { if (type == FcmNotificationType.MISSION) { - return "myapp://mission"; + return DEEP_LINK_PREFIX + "mission"; } else if (type == FcmNotificationType.BOOSTER) { - return "myapp://boost?id=" + targetId; + return DEEP_LINK_PREFIX + "boost?id=" + targetId; } return null; } diff --git a/src/main/java/com/depromeet/stonebed/domain/fcm/dto/response/FcmNotificationDto.java b/src/main/java/com/depromeet/stonebed/domain/fcm/dto/response/FcmNotificationDto.java index 907f27e8..2a09715a 100644 --- a/src/main/java/com/depromeet/stonebed/domain/fcm/dto/response/FcmNotificationDto.java +++ b/src/main/java/com/depromeet/stonebed/domain/fcm/dto/response/FcmNotificationDto.java @@ -15,8 +15,8 @@ public record FcmNotificationDto( String imageUrl, @Schema(description = "읽음 여부", example = "false") Boolean isRead, @Schema(description = "타겟 ID", example = "1") Long targetId, - @Schema(description = "알림 전송 시간", example = "2024-08-17 13:31:19") LocalDateTime createdAt, - @Schema(description = "딥링크 URL", example = "myapp://notification/1") String deepLink) { + @Schema(description = "알림 전송 시간", example = "2024-08-17 13:31:19") + LocalDateTime createdAt) { public static FcmNotificationDto from( FcmNotification notification, MissionRecord missionRecord) { @@ -30,7 +30,6 @@ public static FcmNotificationDto from( imageUrl, notification.getIsRead(), notification.getTargetId(), - notification.getCreatedAt(), - notification.getDeepLink()); + notification.getCreatedAt()); } } diff --git a/src/main/java/com/depromeet/stonebed/domain/sqs/application/SqsMessageService.java b/src/main/java/com/depromeet/stonebed/domain/sqs/application/SqsMessageService.java index cf168dd9..a63fd0c6 100644 --- a/src/main/java/com/depromeet/stonebed/domain/sqs/application/SqsMessageService.java +++ b/src/main/java/com/depromeet/stonebed/domain/sqs/application/SqsMessageService.java @@ -46,11 +46,12 @@ public void sendMessage(Object message) { } } - public void sendBatchMessages(List tokens, String title, String message) { + public void sendBatchMessages( + List tokens, String title, String message, String deepLink) { List entries = new ArrayList<>(); for (String token : tokens) { try { - FcmMessage fcmMessage = FcmMessage.of(title, message, token); + FcmMessage fcmMessage = FcmMessage.of(title, message, token, deepLink); String messageBody = objectMapper.writeValueAsString(fcmMessage); SendMessageBatchRequestEntry entry = SendMessageBatchRequestEntry.builder()