From 78eadb303966eccbcc3761e8bd1627c43d862c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= <103026521+jyk1029@users.noreply.github.com> Date: Sat, 1 Jul 2023 21:10:14 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20::=20(#161)=20=ED=8A=B9=EC=A0=95?= =?UTF-8?q?=20=EA=B7=B8=EB=A3=B9=EB=A7=8C=20=EC=95=8C=EB=A6=BC=20(#230)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️ :: 특정 그룹만 알림 * ♻️ :: Trailling , * ♻️ :: print문 삭제 * ♻️ :: 코드 정렬 * ♻️ :: 리뷰 반영 * ♻️ :: 공백 추가 --- .../detail/api/NotificationDetailApi.kt | 1 + .../service/NotificationDetailApiImpl.kt | 34 +++++++++++++++++-- .../presentation/QueueController.kt | 7 ++++ .../presentation/dto/SpecificGroup.kt | 16 +++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/dto/SpecificGroup.kt diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/api/NotificationDetailApi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/api/NotificationDetailApi.kt index 21520ba..85dad65 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/api/NotificationDetailApi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/api/NotificationDetailApi.kt @@ -6,6 +6,7 @@ import io.github.v1servicenotification.detail.api.dto.response.NotificationCount interface NotificationDetailApi { fun postGroupNotification(topic: String, content: String, threadId: String) + fun postSpecificGroupNotification(userIdList: List, topic: String, content: String,threadId: String) fun postNotification(userId: UUID, topic: String, content: String,threadId: String) fun queryNotificationDetail(userId: UUID): DetailResponse fun queryUnreadNotificationCount(userId: UUID): NotificationCountResponse diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt index ff044d7..64bc76c 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt @@ -43,7 +43,6 @@ class NotificationDetailApiImpl( } val detailList = userIdList - .stream() .map { Detail( title = category.title, @@ -53,7 +52,7 @@ class NotificationDetailApiImpl( userId = it, categoryId = category.id, ) - }.toList() + } postDetailRepositorySpi.saveAllDetail(detailList) @@ -61,7 +60,36 @@ class NotificationDetailApiImpl( postDetailUserSpi.getDeviceTokenList(userIdList), category.title, content, - threadId, + threadId + ) + } + + override fun postSpecificGroupNotification(userIdList: List, topic: String, content: String, threadId: String) { + if (!queryCategoryRepositorySpi.existByTopic(topic)) { + throw CategoryNotFoundException.EXCEPTION + } + + val category = queryCategoryRepositorySpi.findByTopic(topic) + + val detailList = userIdList + .map { + Detail( + title = category.title, + content = content, + sentAt = LocalDateTime.now(), + isRead = false, + userId = it, + categoryId = category.id, + ) + } + + postDetailRepositorySpi.saveAllDetail(detailList) + + postDetailFcmSpi.sendGroupMessage( + postDetailUserSpi.getDeviceTokenList(userIdList), + category.title, + content, + threadId ) } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/QueueController.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/QueueController.kt index 1f9c7d5..2cc3269 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/QueueController.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/QueueController.kt @@ -3,7 +3,9 @@ package io.github.v1servicenotification.domain.notification.presentation import io.github.v1servicenotification.detail.api.NotificationDetailApi import io.github.v1servicenotification.domain.notification.presentation.dto.Group import io.github.v1servicenotification.domain.notification.presentation.dto.Personal +import io.github.v1servicenotification.domain.notification.presentation.dto.SpecificGroup import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy +import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy.ALWAYS import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener import org.springframework.messaging.handler.annotation.Payload import org.springframework.stereotype.Component @@ -19,6 +21,11 @@ class QueueController( notificationDetailApi.postGroupNotification(group.topic, group.content, group.threadId) } + @SqsListener(value = ["specific-group-notification.fifo"], deletionPolicy = SqsMessageDeletionPolicy.ALWAYS) + fun specificGroupNotification(@Payload @Valid specificGroup: SpecificGroup) { + notificationDetailApi.postSpecificGroupNotification(specificGroup.userIdList, specificGroup.topic, specificGroup.content, specificGroup.threadId) + } + @SqsListener(value = ["notification.fifo"], deletionPolicy = SqsMessageDeletionPolicy.ALWAYS) fun notification(@Payload @Valid personal: Personal) { notificationDetailApi.postNotification(personal.userId, personal.topic, personal.content, personal.threadId) diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/dto/SpecificGroup.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/dto/SpecificGroup.kt new file mode 100644 index 0000000..a10120a --- /dev/null +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/notification/presentation/dto/SpecificGroup.kt @@ -0,0 +1,16 @@ +package io.github.v1servicenotification.domain.notification.presentation.dto + +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.UUID + +data class SpecificGroup( + @JsonProperty("user_id_list") + val userIdList: List, + + val topic: String, + + val content: String, + + @JsonProperty("thread_id") + val threadId: String, +)