Skip to content

Commit

Permalink
🔀 :: (#161) 특정 그룹만 알림 (#230)
Browse files Browse the repository at this point in the history
* ♻️ :: 특정 그룹만 알림

* ♻️ :: Trailling ,

* ♻️ :: print문 삭제

* ♻️ :: 코드 정렬

* ♻️ :: 리뷰 반영

* ♻️ :: 공백 추가
  • Loading branch information
jyk1029 authored Jul 1, 2023
1 parent d887a01 commit 78eadb3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID>, 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class NotificationDetailApiImpl(
}

val detailList = userIdList
.stream()
.map {
Detail(
title = category.title,
Expand All @@ -53,15 +52,44 @@ class NotificationDetailApiImpl(
userId = it,
categoryId = category.id,
)
}.toList()
}

postDetailRepositorySpi.saveAllDetail(detailList)

postDetailFcmSpi.sendGroupMessage(
postDetailUserSpi.getDeviceTokenList(userIdList),
category.title,
content,
threadId,
threadId
)
}

override fun postSpecificGroupNotification(userIdList: List<UUID>, 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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UUID>,

val topic: String,

val content: String,

@JsonProperty("thread_id")
val threadId: String,
)

0 comments on commit 78eadb3

Please sign in to comment.