Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: (#527) 알림 삭제 api #528

Merged
merged 5 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ enum class NotificationErrorCode(
private val sequence: Int
) : ErrorProperty {

DEVICE_TOKEN_NOT_FOUND(ErrorStatus.BAD_REQUEST, "Notification Token Not Found", 1)
DEVICE_TOKEN_NOT_FOUND(ErrorStatus.BAD_REQUEST, "Notification Token Not Found", 1),
NOTIFICATION_OF_USER_NOT_FOUND(ErrorStatus.BAD_REQUEST, "NotificationOfUser Not Found", 2)
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ import team.aliens.dms.common.error.DmsException
object DeviceTokenNotFoundException : DmsException(
NotificationErrorCode.DEVICE_TOKEN_NOT_FOUND
)

object NotificationOfUserNotFoundException : DmsException(
NotificationErrorCode.NOTIFICATION_OF_USER_NOT_FOUND
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team.aliens.dms.domain.notification.service

import java.util.UUID
import team.aliens.dms.domain.notification.model.DeviceToken

interface CommandNotificationService {

fun saveDeviceToken(deviceToken: DeviceToken)

fun deleteNotificationOfUserByUserIdAndId(userId: UUID, notificationOfUserId: UUID)

fun deleteNotificationOfUserByUserId(userId: UUID)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package team.aliens.dms.domain.notification.service

import java.util.UUID
import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.notification.exception.NotificationOfUserNotFoundException
import team.aliens.dms.domain.notification.model.DeviceToken
import team.aliens.dms.domain.notification.spi.CommandDeviceTokenPort
import team.aliens.dms.domain.notification.spi.CommandNotificationOfUserPort
import team.aliens.dms.domain.notification.spi.NotificationPort
import team.aliens.dms.domain.notification.spi.QueryNotificationOfUserPort

@Service
class CommandNotificationServiceImpl(
private val deviceTokenPort: CommandDeviceTokenPort,
private val notificationPort: NotificationPort,
private val queryNotificationOfUserPort: QueryNotificationOfUserPort,
private val commandNotificationOfUserPort: CommandNotificationOfUserPort
): CommandNotificationService {

override fun saveDeviceToken(deviceToken: DeviceToken) {
deviceTokenPort.saveDeviceToken(deviceToken)
notificationPort.subscribeAllTopics(
token = deviceToken.token
)
}

override fun deleteNotificationOfUserByUserIdAndId(userId: UUID, notificationOfUserId: UUID) {
queryNotificationOfUserPort.queryNotificationOfUserById(notificationOfUserId).also {
if (it == null || it.userId != userId) {
throw NotificationOfUserNotFoundException
}
}
commandNotificationOfUserPort.deleteNotificationOfUserById(notificationOfUserId)
}

override fun deleteNotificationOfUserByUserId(userId: UUID) {
commandNotificationOfUserPort.deleteNotificationOfUserByUserId(userId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.aliens.dms.domain.notification.service

import java.util.UUID
import team.aliens.dms.domain.notification.model.DeviceToken
import team.aliens.dms.domain.notification.model.NotificationOfUser
import team.aliens.dms.domain.notification.model.TopicSubscription

interface GetNotificationService {

fun getNotificationOfUsersByUserId(userId: UUID): List<NotificationOfUser>

fun getTopicSubscriptionsByToken(token: String): List<TopicSubscription>

fun getDeviceTokenByToken(token: String): DeviceToken
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package team.aliens.dms.domain.notification.service

import java.util.UUID
import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.notification.exception.DeviceTokenNotFoundException
import team.aliens.dms.domain.notification.model.TopicSubscription
import team.aliens.dms.domain.notification.spi.QueryDeviceTokenPort
import team.aliens.dms.domain.notification.spi.QueryNotificationOfUserPort
import team.aliens.dms.domain.notification.spi.QueryTopicSubscriptionPort

@Service
class GetNotificationServiceImpl(
private val deviceTokenPort: QueryDeviceTokenPort,
private val notificationOfUserPort: QueryNotificationOfUserPort,
private val topicSubscriptionPort: QueryTopicSubscriptionPort
): GetNotificationService {

override fun getNotificationOfUsersByUserId(userId: UUID) =
notificationOfUserPort.queryNotificationOfUserByUserId(userId)

override fun getTopicSubscriptionsByToken(token: String): List<TopicSubscription> {
val savedToken = getDeviceTokenByToken(token)
return topicSubscriptionPort.queryTopicSubscriptionsByDeviceTokenId(savedToken.id)
}

override fun getDeviceTokenByToken(token: String) =
deviceTokenPort.queryDeviceTokenByToken(token) ?: throw DeviceTokenNotFoundException
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package team.aliens.dms.domain.notification.service

import team.aliens.dms.domain.notification.model.DeviceToken
import team.aliens.dms.domain.notification.model.Notification
import team.aliens.dms.domain.notification.model.NotificationOfUser
import team.aliens.dms.domain.notification.model.Topic
import team.aliens.dms.domain.notification.model.TopicSubscription
import java.util.UUID

interface NotificationService {

fun saveDeviceToken(deviceToken: DeviceToken)
interface NotificationService:
GetNotificationService,
CommandNotificationService {

fun unsubscribeTopic(token: String, topic: Topic)

Expand All @@ -27,8 +24,4 @@ interface NotificationService {
fun sendMessagesByTopic(
notification: Notification
)

fun getNotificationOfUsersByUserId(userId: UUID): List<NotificationOfUser>

fun getTopicSubscriptionsByToken(token: String): List<TopicSubscription>
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
package team.aliens.dms.domain.notification.service

import org.springframework.stereotype.Component
import team.aliens.dms.domain.notification.exception.DeviceTokenNotFoundException
import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.notification.model.DeviceToken
import team.aliens.dms.domain.notification.model.Notification
import team.aliens.dms.domain.notification.model.Topic
import team.aliens.dms.domain.notification.model.TopicSubscription
import team.aliens.dms.domain.notification.spi.DeviceTokenPort
import team.aliens.dms.domain.notification.spi.NotificationOfUserPort
import team.aliens.dms.domain.notification.spi.CommandNotificationOfUserPort
import team.aliens.dms.domain.notification.spi.CommandTopicSubscriptionPort
import team.aliens.dms.domain.notification.spi.NotificationPort
import team.aliens.dms.domain.notification.spi.TopicSubscriptionPort
import team.aliens.dms.domain.user.spi.UserPort
import java.util.UUID
import team.aliens.dms.domain.user.spi.QueryUserPort

@Component
@Service
class NotificationServiceImpl(
private val notificationPort: NotificationPort,
private val notificationOfUserPort: NotificationOfUserPort,
private val userPort: UserPort,
private val topicSubscriptionPort: TopicSubscriptionPort,
private val deviceTokenPort: DeviceTokenPort
) : NotificationService {

override fun saveDeviceToken(deviceToken: DeviceToken) {
deviceTokenPort.saveDeviceToken(deviceToken)
notificationPort.subscribeAllTopics(
token = deviceToken.token
)
}
private val queryUserPort: QueryUserPort,
private val commandTopicSubscriptionPort: CommandTopicSubscriptionPort,
private val notificationOfUserPort: CommandNotificationOfUserPort,
getNotificationService: GetNotificationService,
commandNotificationService: CommandNotificationService
) : NotificationService,
GetNotificationService by getNotificationService,
CommandNotificationService by commandNotificationService{

override fun subscribeTopic(token: String, topic: Topic) {
val deviceToken = this.getDeviceTokenByToken(token)
topicSubscriptionPort.saveTopicSubscription(
commandTopicSubscriptionPort.saveTopicSubscription(
TopicSubscription.subscribe(
deviceTokenId = deviceToken.id,
topic = topic,
Expand All @@ -45,7 +38,7 @@ class NotificationServiceImpl(

override fun unsubscribeTopic(token: String, topic: Topic) {
val deviceToken = this.getDeviceTokenByToken(token)
topicSubscriptionPort.saveTopicSubscription(
commandTopicSubscriptionPort.saveTopicSubscription(
TopicSubscription.unsubscribe(
deviceTokenId = deviceToken.id,
topic = topic,
Expand All @@ -67,7 +60,7 @@ class NotificationServiceImpl(
isSubscribed = isSubscribe
)
}
topicSubscriptionPort.saveAllTopicSubscriptions(topicSubscriptions)
commandTopicSubscriptionPort.saveAllTopicSubscriptions(topicSubscriptions)
}

private fun subscribeOrUnsubscribeTopic(
Expand All @@ -88,9 +81,6 @@ class NotificationServiceImpl(
}
}

private fun getDeviceTokenByToken(token: String) =
deviceTokenPort.queryDeviceTokenByToken(token) ?: throw DeviceTokenNotFoundException

override fun sendMessage(deviceToken: DeviceToken, notification: Notification) {
notification.runIfSaveRequired {
notificationOfUserPort.saveNotificationOfUser(
Expand All @@ -117,7 +107,7 @@ class NotificationServiceImpl(

override fun sendMessagesByTopic(notification: Notification) {
notification.runIfSaveRequired {
val users = userPort.queryUsersBySchoolId(notification.schoolId)
val users = queryUserPort.queryUsersBySchoolId(notification.schoolId)
notificationOfUserPort.saveNotificationsOfUser(
users.map { notification.toNotificationOfUser(it.id) }
)
Expand All @@ -126,12 +116,4 @@ class NotificationServiceImpl(
notification = notification
)
}

override fun getNotificationOfUsersByUserId(userId: UUID) =
notificationOfUserPort.queryNotificationOfUserByUserId(userId)

override fun getTopicSubscriptionsByToken(token: String): List<TopicSubscription> {
val savedToken = getDeviceTokenByToken(token)
return topicSubscriptionPort.queryTopicSubscriptionsByDeviceTokenId(savedToken.id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.aliens.dms.domain.notification.spi

import java.util.UUID
import team.aliens.dms.domain.notification.model.DeviceToken

interface CommandDeviceTokenPort {

fun saveDeviceToken(deviceToken: DeviceToken): DeviceToken

fun deleteDeviceTokenByUserId(userId: UUID)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.aliens.dms.domain.notification.spi

import java.util.UUID
import team.aliens.dms.domain.notification.model.NotificationOfUser

interface CommandNotificationOfUserPort {

fun saveNotificationOfUser(notificationOfUser: NotificationOfUser): NotificationOfUser

fun saveNotificationsOfUser(notificationsOfUser: List<NotificationOfUser>)

fun deleteNotificationOfUserById(notificationOfUserId: UUID)

fun deleteNotificationOfUserByUserId(userId: UUID)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.aliens.dms.domain.notification.spi

import team.aliens.dms.domain.notification.model.TopicSubscription

interface CommandTopicSubscriptionPort {

fun saveTopicSubscription(topicSubscription: TopicSubscription): TopicSubscription

fun saveAllTopicSubscriptions(topicSubscriptions: List<TopicSubscription>)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package team.aliens.dms.domain.notification.spi

import team.aliens.dms.domain.notification.model.DeviceToken
import java.util.UUID

interface DeviceTokenPort {

fun saveDeviceToken(deviceToken: DeviceToken): DeviceToken

fun queryDeviceTokenByUserId(userId: UUID): DeviceToken?

fun queryDeviceTokenByToken(token: String): DeviceToken?

fun deleteDeviceTokenByUserId(userId: UUID)
}
interface DeviceTokenPort :
QueryDeviceTokenPort,
CommandDeviceTokenPort
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package team.aliens.dms.domain.notification.spi

import team.aliens.dms.domain.notification.model.NotificationOfUser
import java.util.UUID

interface NotificationOfUserPort {

fun saveNotificationOfUser(notificationOfUser: NotificationOfUser): NotificationOfUser

fun saveNotificationsOfUser(notificationsOfUser: List<NotificationOfUser>)

fun queryNotificationOfUserByUserId(userId: UUID): List<NotificationOfUser>
}
interface NotificationOfUserPort :
QueryNotificationOfUserPort,
CommandNotificationOfUserPort
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.aliens.dms.domain.notification.spi

import java.util.UUID
import team.aliens.dms.domain.notification.model.DeviceToken

interface QueryDeviceTokenPort {

fun queryDeviceTokenByUserId(userId: UUID): DeviceToken?

fun queryDeviceTokenByToken(token: String): DeviceToken?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.aliens.dms.domain.notification.spi

import java.util.UUID
import team.aliens.dms.domain.notification.model.NotificationOfUser

interface QueryNotificationOfUserPort {

fun queryNotificationOfUserByUserId(userId: UUID): List<NotificationOfUser>

fun queryNotificationOfUserById(notificationOfUserId: UUID): NotificationOfUser?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.aliens.dms.domain.notification.spi

import java.util.UUID
import team.aliens.dms.domain.notification.model.TopicSubscription

interface QueryTopicSubscriptionPort {

fun queryTopicSubscriptionsByDeviceTokenId(deviceTokenId: UUID): List<TopicSubscription>
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package team.aliens.dms.domain.notification.spi

import team.aliens.dms.domain.notification.model.TopicSubscription
import java.util.UUID
interface TopicSubscriptionPort :
QueryTopicSubscriptionPort,
CommandTopicSubscriptionPort

interface TopicSubscriptionPort {

fun saveTopicSubscription(topicSubscription: TopicSubscription): TopicSubscription

fun queryTopicSubscriptionsByDeviceTokenId(deviceTokenId: UUID): List<TopicSubscription>

fun saveAllTopicSubscriptions(topicSubscriptions: List<TopicSubscription>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package team.aliens.dms.domain.notification.usecase

import team.aliens.dms.common.annotation.UseCase
import team.aliens.dms.domain.notification.service.NotificationService
import team.aliens.dms.domain.user.service.UserService

@UseCase
class RemoveMyAllNotificationUseCase(
private val userService: UserService,
private val notificationService: NotificationService
) {

fun execute() {
val user = userService.getCurrentUser()
notificationService.deleteNotificationOfUserByUserId(user.id)
}
}
Loading