From b246ec19008298b8155f0f437bc7c4a8659c92e5 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Fri, 12 May 2023 01:58:24 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20::=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicenotification/error/ErrorCode.kt | 2 + .../NotificationDeviceTokenLengthException.kt | 9 ++ .../global/fcm/FcmService.kt | 86 +++++++++++-------- 3 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt index 3bb57967..5c4e36fb 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt @@ -21,4 +21,6 @@ enum class ErrorCode( DETAIL_NOT_FOUND(404, "DETAIL-404-1", "Detail Not Found."), INTERNAL_SERVER_ERROR(500, "GLOBAL-500-1", "Internal Server Error."), + + DEVICE_TOKEN_LENGTH(400, "DEVICE-400-1", "Device Token Length Error."); } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt new file mode 100644 index 00000000..21e846c7 --- /dev/null +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt @@ -0,0 +1,9 @@ +package io.github.v1servicenotification.error + +class NotificationDeviceTokenLengthException private constructor(): NotificationException(ErrorCode.DETAIL_NOT_FOUND) { + + companion object { + @JvmField + val EXCEPTION = NotificationDeviceTokenLengthException() + } +} diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt index 0c9596a3..b44c6ce1 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt @@ -7,53 +7,63 @@ import com.google.firebase.messaging.Message import com.google.firebase.messaging.MulticastMessage import com.google.firebase.messaging.Notification import io.github.v1servicenotification.detail.spi.PostDetailFcmSpi +import io.github.v1servicenotification.error.NotificationDeviceTokenLengthException +import io.github.v1servicenotification.error.NotificationException import org.springframework.stereotype.Service @Service class FcmService: PostDetailFcmSpi { override fun sendGroupMessage(tokenList: List, title: String, content: String, threadId: String) { - val multicast = MulticastMessage.builder() - .addAllTokens(tokenList) - .setNotification( - Notification.builder() - .setTitle(title) - .setBody(content) - .build() - ) - .setApnsConfig( - ApnsConfig.builder() - .setAps( - Aps.builder() - .setSound("default") - .setThreadId(threadId) - .build() - ).build() - ) - .build() + val validTokens = tokenList.filter { it.length == 163 } + if (validTokens.isNotEmpty()) { + val multicast = MulticastMessage.builder() + .addAllTokens(validTokens) + .setNotification( + Notification.builder() + .setTitle(title) + .setBody(content) + .build() + ) + .setApnsConfig( + ApnsConfig.builder() + .setAps( + Aps.builder() + .setSound("default") + .setThreadId(threadId) + .build() + ).build() + ) + .build() - FirebaseMessaging.getInstance().sendMulticastAsync(multicast) + FirebaseMessaging.getInstance().sendMulticastAsync(multicast) + } } override fun sendMessage(token: String, title: String, content: String, threadId: String) { - val message = Message.builder() - .setToken(token) - .setNotification( - Notification.builder() - .setTitle(title) - .setBody(content) - .build() - ) - .setApnsConfig( - ApnsConfig.builder() - .setAps( - Aps.builder() - .setSound("default") - .setThreadId(threadId) - .build() - ).build() - ) - .build() - FirebaseMessaging.getInstance().sendAsync(message) + if (token.length >= 163) { + val message = Message.builder() + .setToken(token) + .setNotification( + Notification.builder() + .setTitle(title) + .setBody(content) + .build() + ) + .setApnsConfig( + ApnsConfig.builder() + .setAps( + Aps.builder() + .setSound("default") + .setThreadId(threadId) + .build() + ).build() + ) + .build() + FirebaseMessaging.getInstance().sendAsync(message) + } else { + throw NotificationDeviceTokenLengthException.EXCEPTION + } } + } From b38bd65f62db7e8089fcaf93ac24979d02efe180 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Fri, 12 May 2023 02:00:32 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/v1servicenotification/error/ErrorCode.kt | 2 +- .../error/NotificationDeviceTokenLengthException.kt | 2 +- .../v1servicenotification/global/fcm/FcmService.kt | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt index 5c4e36fb..07b88e0b 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt @@ -22,5 +22,5 @@ enum class ErrorCode( INTERNAL_SERVER_ERROR(500, "GLOBAL-500-1", "Internal Server Error."), - DEVICE_TOKEN_LENGTH(400, "DEVICE-400-1", "Device Token Length Error."); + DEVICE_TOKEN_LENGTH(400, "DEVICE-400-1", "Device Token Length Error.") } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt index 21e846c7..0f5d062b 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt @@ -1,6 +1,6 @@ package io.github.v1servicenotification.error -class NotificationDeviceTokenLengthException private constructor(): NotificationException(ErrorCode.DETAIL_NOT_FOUND) { +class NotificationDeviceTokenLengthException private constructor(): NotificationException(ErrorCode.DEVICE_TOKEN_LENGTH) { companion object { @JvmField diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt index b44c6ce1..1f7452cf 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt @@ -8,14 +8,17 @@ import com.google.firebase.messaging.MulticastMessage import com.google.firebase.messaging.Notification import io.github.v1servicenotification.detail.spi.PostDetailFcmSpi import io.github.v1servicenotification.error.NotificationDeviceTokenLengthException -import io.github.v1servicenotification.error.NotificationException import org.springframework.stereotype.Service @Service class FcmService: PostDetailFcmSpi { + companion object { + const val MAX_TOKEN_LENGTH = 163 + } + override fun sendGroupMessage(tokenList: List, title: String, content: String, threadId: String) { - val validTokens = tokenList.filter { it.length == 163 } + val validTokens = tokenList.filter { it.length == MAX_TOKEN_LENGTH } if (validTokens.isNotEmpty()) { val multicast = MulticastMessage.builder() .addAllTokens(validTokens) @@ -41,7 +44,7 @@ class FcmService: PostDetailFcmSpi { } override fun sendMessage(token: String, title: String, content: String, threadId: String) { - if (token.length >= 163) { + if (token.length >= MAX_TOKEN_LENGTH) { val message = Message.builder() .setToken(token) .setNotification( From 3b921a3ae13305b5a795904684ea3848959ea57d Mon Sep 17 00:00:00 2001 From: lyutvs Date: Fri, 12 May 2023 02:01:30 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../error/InvalidDeviceTokenLengthException.kt | 9 +++++++++ .../error/NotificationDeviceTokenLengthException.kt | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 notification-domain/src/main/kotlin/io/github/v1servicenotification/error/InvalidDeviceTokenLengthException.kt delete mode 100644 notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/InvalidDeviceTokenLengthException.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/InvalidDeviceTokenLengthException.kt new file mode 100644 index 00000000..6f8a8bf4 --- /dev/null +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/InvalidDeviceTokenLengthException.kt @@ -0,0 +1,9 @@ +package io.github.v1servicenotification.error + +class InvalidDeviceTokenLengthException private constructor(): NotificationException(ErrorCode.DEVICE_TOKEN_LENGTH) { + + companion object { + @JvmField + val EXCEPTION = InvalidDeviceTokenLengthException() + } +} diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt deleted file mode 100644 index 0f5d062b..00000000 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/NotificationDeviceTokenLengthException.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.github.v1servicenotification.error - -class NotificationDeviceTokenLengthException private constructor(): NotificationException(ErrorCode.DEVICE_TOKEN_LENGTH) { - - companion object { - @JvmField - val EXCEPTION = NotificationDeviceTokenLengthException() - } -} From 560c0fc219b47521fcbfb630780c6431ad0d678f Mon Sep 17 00:00:00 2001 From: lyutvs Date: Fri, 12 May 2023 02:01:36 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/io/github/v1servicenotification/error/ErrorCode.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt index 07b88e0b..03ec9d7e 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt @@ -22,5 +22,5 @@ enum class ErrorCode( INTERNAL_SERVER_ERROR(500, "GLOBAL-500-1", "Internal Server Error."), - DEVICE_TOKEN_LENGTH(400, "DEVICE-400-1", "Device Token Length Error.") + DEVICE_TOKEN_LENGTH(401, "DEVICE-400-1", "Device Token Length Error.") } From 81366d451f5f7b54609bc69d8b4df783ca4a4c4d Mon Sep 17 00:00:00 2001 From: lyutvs Date: Fri, 12 May 2023 02:01:52 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=9E=84?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/v1servicenotification/global/fcm/FcmService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt index 1f7452cf..2e0d0f5d 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/global/fcm/FcmService.kt @@ -7,7 +7,7 @@ import com.google.firebase.messaging.Message import com.google.firebase.messaging.MulticastMessage import com.google.firebase.messaging.Notification import io.github.v1servicenotification.detail.spi.PostDetailFcmSpi -import io.github.v1servicenotification.error.NotificationDeviceTokenLengthException +import io.github.v1servicenotification.error.InvalidDeviceTokenLengthException import org.springframework.stereotype.Service @Service @@ -65,7 +65,7 @@ class FcmService: PostDetailFcmSpi { .build() FirebaseMessaging.getInstance().sendAsync(message) } else { - throw NotificationDeviceTokenLengthException.EXCEPTION + throw InvalidDeviceTokenLengthException.EXCEPTION } }