diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/BaseTimeEntity.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/BaseTimeEntity.kt index aa36a325..2df83fc6 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/BaseTimeEntity.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/BaseTimeEntity.kt @@ -14,9 +14,9 @@ abstract class BaseTimeEntity { @CreatedDate @Column(updatable = false) - var createdAt: LocalDateTime = LocalDateTime.now() + open var createdAt: LocalDateTime = LocalDateTime.now() @LastModifiedDate @Column(updatable = true) - var updatedAt: LocalDateTime = LocalDateTime.now() + open var updatedAt: LocalDateTime = LocalDateTime.now() } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt index bac5de2c..f3c27f55 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt @@ -54,7 +54,7 @@ class PromiseImage( @PostPersist fun createImageEvent() { - Events.raise(PromiseImageRegisterEvent(userId, promiseId)) + Events.raise(PromiseImageRegisterEvent(userId, promiseId, imageKey)) } fun validateOwnership(userId: Long) { diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/EndSharingNotification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/EndSharingNotification.kt new file mode 100644 index 00000000..027cd116 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/EndSharingNotification.kt @@ -0,0 +1,12 @@ +package com.depromeet.whatnow.domains.notification.domain + +import javax.persistence.DiscriminatorValue +import javax.persistence.Entity + +@Entity +@DiscriminatorValue("END_SHARING") +class EndSharingNotification( + var promiseId: Long, + + override var targetUserId: Long, +) : Notification(targetUserId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/ImageNotification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/ImageNotification.kt new file mode 100644 index 00000000..bc573d3f --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/ImageNotification.kt @@ -0,0 +1,22 @@ +package com.depromeet.whatnow.domains.notification.domain + +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType +import javax.persistence.DiscriminatorValue +import javax.persistence.Entity +import javax.persistence.EnumType +import javax.persistence.Enumerated + +@Entity +@DiscriminatorValue("IMAGE") +class ImageNotification( + @Enumerated(EnumType.STRING) + var senderUserPromiseUserType: PromiseUserType, + + var senderUserId: Long, + + var promiseId: Long, + + var imageKey: String, + + override var targetUserId: Long, +) : Notification(targetUserId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/InteractionAttainmentNotification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/InteractionAttainmentNotification.kt new file mode 100644 index 00000000..e8e530a1 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/InteractionAttainmentNotification.kt @@ -0,0 +1,17 @@ +package com.depromeet.whatnow.domains.notification.domain + +import com.depromeet.whatnow.domains.interaction.domain.InteractionType +import javax.persistence.DiscriminatorValue +import javax.persistence.Entity + +@Entity +@DiscriminatorValue("INTERACTION_ATTAINMENT") +class InteractionAttainmentNotification( + var promiseId: Long, + + var senderUserId: Long, + + var interactionType: InteractionType, + + override var targetUserId: Long, +) : Notification(targetUserId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/InteractionNotification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/InteractionNotification.kt new file mode 100644 index 00000000..a6e3fb7c --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/InteractionNotification.kt @@ -0,0 +1,17 @@ +package com.depromeet.whatnow.domains.notification.domain + +import com.depromeet.whatnow.domains.interaction.domain.InteractionType +import javax.persistence.DiscriminatorValue +import javax.persistence.Entity + +@Entity +@DiscriminatorValue("INTERACTION") +class InteractionNotification( + var promiseId: Long, + + var senderUserId: Long, + + var interactionType: InteractionType, + + override var targetUserId: Long, +) : Notification(targetUserId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt index f5061040..4d8d8cf3 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt @@ -1,111 +1,26 @@ package com.depromeet.whatnow.domains.notification.domain import com.depromeet.whatnow.common.BaseTimeEntity -import com.depromeet.whatnow.domains.interaction.domain.InteractionType -import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import javax.persistence.Column -import javax.persistence.ElementCollection +import javax.persistence.DiscriminatorColumn +import javax.persistence.DiscriminatorType import javax.persistence.Entity -import javax.persistence.EnumType -import javax.persistence.Enumerated import javax.persistence.GeneratedValue import javax.persistence.GenerationType import javax.persistence.Id +import javax.persistence.Inheritance +import javax.persistence.InheritanceType import javax.persistence.Table @Entity @Table(name = "tbl_notification") -class Notification( - @Enumerated(EnumType.STRING) - var notificationType: NotificationType, - - @Enumerated(EnumType.STRING) - var interactionType: InteractionType?, - - @Enumerated(EnumType.STRING) - var promiseUserType: PromiseUserType?, - - var userId: Long?, - - @ElementCollection - var targetUserIds: Set, - - var targetId: Long?, +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "notification_type", discriminatorType = DiscriminatorType.STRING) +abstract class Notification( + open val targetUserId: Long, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "notification_id") - val id: Long? = null, -) : BaseTimeEntity() { - companion object { - fun createForImage(userId: Long, targetUserId: Set, promiseImageId: Long): Notification { - return Notification( - notificationType = NotificationType.IMAGE, - userId = userId, - targetUserIds = targetUserId, - targetId = promiseImageId, - interactionType = null, - promiseUserType = null, - ) - } - - fun createForStartSharing(targetUserIds: Set, promiseId: Long): Notification { - return Notification( - notificationType = NotificationType.START_SHARING, - userId = null, - targetUserIds = targetUserIds, - targetId = promiseId, - interactionType = null, - promiseUserType = null, - ) - } - - fun createForEndSharing(targetUserIds: Set, promiseId: Long): Notification { - return Notification( - notificationType = NotificationType.END_SHARING, - userId = null, - targetUserIds = targetUserIds, - targetId = promiseId, - interactionType = null, - promiseUserType = null, - ) - } - - fun createForTimeOver(targetUserIds: Set, promiseId: Long): Notification { - return Notification( - notificationType = NotificationType.TIMEOVER, - userId = null, - targetUserIds = targetUserIds, - targetId = promiseId, - interactionType = null, - promiseUserType = null, - ) - } - - fun createForInteraction(userId: Long, targetUserId: Long, interactionType: InteractionType): Notification { - return Notification( - notificationType = NotificationType.INTERACTION, - userId = userId, - targetUserIds = mutableSetOf(targetUserId), - targetId = null, - interactionType = interactionType, - promiseUserType = null, - ) - } - - fun createForInteractionAttainment( - userId: Long, - senderUserIds: Set, - interactionType: InteractionType, - ): Notification { - return Notification( - notificationType = NotificationType.INTERACTION_ATTAINMENT, - userId = userId, - targetUserIds = senderUserIds, - targetId = null, - interactionType = interactionType, - promiseUserType = null, - ) - } - } -} + open val id: Long? = null, +) : BaseTimeEntity() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/StartSharingNotification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/StartSharingNotification.kt new file mode 100644 index 00000000..ac60544d --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/StartSharingNotification.kt @@ -0,0 +1,12 @@ +package com.depromeet.whatnow.domains.notification.domain + +import javax.persistence.DiscriminatorValue +import javax.persistence.Entity + +@Entity +@DiscriminatorValue("START_SHARING") +class StartSharingNotification( + var promiseId: Long, + + override var targetUserId: Long, +) : Notification(targetUserId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/TimeOverNotification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/TimeOverNotification.kt new file mode 100644 index 00000000..320afc3e --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/TimeOverNotification.kt @@ -0,0 +1,15 @@ +package com.depromeet.whatnow.domains.notification.domain + +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType +import javax.persistence.DiscriminatorValue +import javax.persistence.Entity + +@Entity +@DiscriminatorValue("TIMEOVER") +class TimeOverNotification( + var promiseId: Long, + + var promiseUserType: PromiseUserType, + + override var targetUserId: Long, +) : Notification(targetUserId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt index 74995c81..0d8e7a58 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt @@ -2,7 +2,13 @@ package com.depromeet.whatnow.domains.notification.service import com.depromeet.whatnow.domains.interaction.domain.InteractionType import com.depromeet.whatnow.domains.notification.adapter.NotificationAdapter -import com.depromeet.whatnow.domains.notification.domain.Notification +import com.depromeet.whatnow.domains.notification.domain.EndSharingNotification +import com.depromeet.whatnow.domains.notification.domain.ImageNotification +import com.depromeet.whatnow.domains.notification.domain.InteractionAttainmentNotification +import com.depromeet.whatnow.domains.notification.domain.InteractionNotification +import com.depromeet.whatnow.domains.notification.domain.StartSharingNotification +import com.depromeet.whatnow.domains.notification.domain.TimeOverNotification +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -11,32 +17,32 @@ class NotificationDomainService( val notificationAdapter: NotificationAdapter, ) { @Transactional - fun saveForImage(userId: Long, targetUserId: Set, promiseImageId: Long) { - notificationAdapter.save(Notification.createForImage(userId, targetUserId, promiseImageId)) + fun saveForImage(senderPromiseUserType: PromiseUserType, userId: Long, targetUserId: Long, promiseId: Long, imageKey: String) { + notificationAdapter.save(ImageNotification(senderPromiseUserType, userId, promiseId, imageKey, targetUserId)) } @Transactional - fun saveForStartSharing(targetUserIds: Set, promiseId: Long) { - notificationAdapter.save(Notification.createForStartSharing(targetUserIds, promiseId)) + fun saveForStartSharing(promiseId: Long, targetUserId: Long) { + notificationAdapter.save(StartSharingNotification(promiseId, targetUserId)) } @Transactional - fun saveForEndSharing(targetUserIds: Set, promiseId: Long) { - notificationAdapter.save(Notification.createForEndSharing(targetUserIds, promiseId)) + fun saveForEndSharing(promiseId: Long, targetUserId: Long) { + notificationAdapter.save(EndSharingNotification(promiseId, targetUserId)) } @Transactional - fun saveForTimeOver(targetUserIds: Set, promiseId: Long) { - notificationAdapter.save(Notification.createForTimeOver(targetUserIds, promiseId)) + fun saveForTimeOver(promiseId: Long, promiseUserType: PromiseUserType, targetUserId: Long) { + notificationAdapter.save(TimeOverNotification(promiseId, promiseUserType, targetUserId)) } @Transactional - fun saveForInteraction(userId: Long, targetUserId: Long, interactionType: InteractionType) { - notificationAdapter.save(Notification.createForInteraction(userId, targetUserId, interactionType)) + fun saveForInteraction(promiseId: Long, senderUserId: Long, interactionType: InteractionType, targetUserId: Long) { + notificationAdapter.save(InteractionNotification(promiseId, senderUserId, interactionType, targetUserId)) } @Transactional - fun saveForInteractionAttainment(userId: Long, senderUserIds: Set, interactionType: InteractionType) { - notificationAdapter.save(Notification.createForInteractionAttainment(userId, senderUserIds, interactionType)) + fun saveForInteractionAttainment(promiseId: Long, senderUserId: Long, interactionType: InteractionType, targetUserId: Long) { + notificationAdapter.save(InteractionAttainmentNotification(promiseId, senderUserId, interactionType, targetUserId)) } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/handler/PromiseUserRegisterHistoryInitHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/handler/PromiseUserRegisterHistoryInitHandler.kt deleted file mode 100644 index eda628bb..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/handler/PromiseUserRegisterHistoryInitHandler.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.depromeet.whatnow.domains.progresshistory.handler - -import com.depromeet.whatnow.annotation.Handler -import com.depromeet.whatnow.domains.progresshistory.service.ProgressHistoryDomainService -import com.depromeet.whatnow.events.domainEvent.PromiseUserRegisterEvent -import mu.KLogger -import mu.KotlinLogging -import org.springframework.transaction.event.TransactionPhase -import org.springframework.transaction.event.TransactionalEventListener - -@Handler -class PromiseUserRegisterHistoryInitHandler( - val progressHistoryDomainService: ProgressHistoryDomainService, -) { - val logger: KLogger = KotlinLogging.logger {} - - @TransactionalEventListener(classes = [PromiseUserRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleDoneOrderEvent(event: PromiseUserRegisterEvent) { - logger.info { "PromiseUserRegisterHistoryInitHandler 이벤트 수신 ${event.promiseId} , 유저아이디 ${event.userId}" } - - progressHistoryDomainService.initHistory(event.promiseId, event.userId) - } -} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt index 4a36457e..b36944a4 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt @@ -5,4 +5,5 @@ import com.depromeet.whatnow.common.aop.event.DomainEvent class PromiseImageRegisterEvent( val userId: Long, val promiseId: Long, + val imageKey: String, ) : DomainEvent() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt index b8e0ab37..7748c293 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt @@ -25,6 +25,7 @@ class ImageRegisterEventHandler( fun handlePromiseImageRegisterEvent(promiseImageRegisterEvent: PromiseImageRegisterEvent) { val userId: Long = promiseImageRegisterEvent.userId val promiseId: Long = promiseImageRegisterEvent.promiseId + val imageKey: String = promiseImageRegisterEvent.imageKey // 사진을 보낸 유저가 Late인지 Wait인지 확인하기 위한 PromiseUser 조회 val promiseUser = promiseUserAdapter.findByPromiseIdAndUserId(promiseId, userId) @@ -42,6 +43,7 @@ class ImageRegisterEventHandler( val data: MutableMap = mutableMapOf() data["notificationType"] = NotificationType.IMAGE.name data["promiseId"] = promiseId.toString() + data["imageKey"] = imageKey // 앱 알람 허용한 유저에게 알람 보내기 when (promiseUser.promiseUserType) { @@ -64,7 +66,15 @@ class ImageRegisterEventHandler( } // notification 저장 - val targetUserIds = usersExcludingSelf.map { user -> user.id!! }.toSet() - notificationDomainService.saveForImage(userId, targetUserIds, promiseId) + usersExcludingSelf + .forEach { targetUser -> + notificationDomainService.saveForImage( + promiseUser.promiseUserType, + userId, + targetUser.id!!, + promiseId, + imageKey, + ) + } } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt index 6d912fcb..d53257d1 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt @@ -32,12 +32,6 @@ class InteractionFixedEventHandler( val user = userAdapter.queryUser(userId) - val senderUserIds = - interactionHistoryDomainService.queryAllByInteractionType(userId, promiseId, interactionType) - .map { interactionHistory -> interactionHistory.targetUserId } - .distinct() - .toSet() - val data: MutableMap = mutableMapOf() data["notificationType"] = NotificationType.INTERACTION_ATTAINMENT.name data["promiseId"] = event.promiseId.toString() @@ -51,6 +45,11 @@ class InteractionFixedEventHandler( ) } - notificationDomainService.saveForInteractionAttainment(userId, senderUserIds, interactionType) + interactionHistoryDomainService.queryAllByInteractionType(userId, promiseId, interactionType) + .map { interactionHistory -> interactionHistory.targetUserId } + .distinct() + .forEach { targetUserId -> + notificationDomainService.saveForInteractionAttainment(promiseId, userId, interactionType, targetUserId) + } } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt index 4c653980..79f6c01f 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt @@ -55,6 +55,6 @@ class InteractionHistoryRegisterHandler( data, ) - notificationDomainService.saveForInteraction(user.id!!, targetUser.id!!, event.interactionType) + notificationDomainService.saveForInteraction(event.promiseId, user.id!!, event.interactionType, targetUser.id!!) } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt index e718581b..4725b10d 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt @@ -97,8 +97,9 @@ class PromiseTimeEndEventHandler( ) // notification 저장 - val targetUserIds = users.map { user -> user.id!! }.toSet() - notificationDomainService.saveForTimeOver(targetUserIds, promiseId) + promiseUsers.forEach { promiseUser -> + notificationDomainService.saveForTimeOver(promiseId, promiseUser.promiseUserType, promiseUser.userId) + } } @Async diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt index f11a5072..d71d20d6 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt @@ -52,7 +52,8 @@ class PromiseTimeStartEventHandler( ) // notification 저장 - val targetUserIds = users.map { user -> user.id!! }.toSet() - notificationDomainService.saveForStartSharing(targetUserIds, promiseId) + users.forEach { user -> + notificationDomainService.saveForStartSharing(promiseId, user.id!!) + } } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt index e43e62dd..7a5612ec 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt @@ -53,7 +53,8 @@ class PromiseTrackingTimeEndEventHandler( ) // notification 저장 - val targetUserIds = users.map { user -> user.id!! }.toSet() - notificationDomainService.saveForEndSharing(targetUserIds, promiseId) + users.forEach { user -> + notificationDomainService.saveForEndSharing(promiseId, user.id!!) + } } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/handler/PromiseUserRegisterHistoryCancelHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserCancelHandler.kt similarity index 80% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/handler/PromiseUserRegisterHistoryCancelHandler.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserCancelHandler.kt index 80d1c9b8..8f0c1279 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/handler/PromiseUserRegisterHistoryCancelHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserCancelHandler.kt @@ -1,21 +1,23 @@ -package com.depromeet.whatnow.domains.progresshistory.handler +package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.annotation.Handler import com.depromeet.whatnow.domains.progresshistory.service.ProgressHistoryDomainService import com.depromeet.whatnow.events.domainEvent.PromiseUserCancelEvent import mu.KLogger import mu.KotlinLogging +import org.springframework.scheduling.annotation.Async import org.springframework.transaction.event.TransactionPhase import org.springframework.transaction.event.TransactionalEventListener @Handler -class PromiseUserRegisterHistoryCancelHandler( +class PromiseUserCancelHandler( val progressHistoryDomainService: ProgressHistoryDomainService, ) { val logger: KLogger = KotlinLogging.logger {} + @Async @TransactionalEventListener(classes = [PromiseUserCancelEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleDoneOrderEvent(event: PromiseUserCancelEvent) { + fun handlePromiseUserCancelEvent(event: PromiseUserCancelEvent) { logger.info { "PromiseUserRegisterHistoryCancelHandler 이벤트 수신 ${event.promiseId} , 유저아이디 ${event.userId}" } progressHistoryDomainService.deleteHistory(event.promiseId, event.userId) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterInteractionInitHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterHandler.kt similarity index 54% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterInteractionInitHandler.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterHandler.kt index 1aae8e3d..6e7f1963 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterInteractionInitHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterHandler.kt @@ -2,20 +2,32 @@ package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.annotation.Handler import com.depromeet.whatnow.domains.interaction.service.InteractionDomainService +import com.depromeet.whatnow.domains.progresshistory.service.ProgressHistoryDomainService import com.depromeet.whatnow.events.domainEvent.PromiseUserRegisterEvent import mu.KLogger import mu.KotlinLogging +import org.springframework.scheduling.annotation.Async import org.springframework.transaction.event.TransactionPhase import org.springframework.transaction.event.TransactionalEventListener @Handler -class PromiseUserRegisterInteractionInitHandler( +class PromiseUserRegisterHandler( + val progressHistoryDomainService: ProgressHistoryDomainService, val interactionDomainService: InteractionDomainService, ) { val logger: KLogger = KotlinLogging.logger {} + @Async @TransactionalEventListener(classes = [PromiseUserRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handlePromiseUserRegisterEvent(event: PromiseUserRegisterEvent) { + fun handlePromiseUserRegisterEventHistory(event: PromiseUserRegisterEvent) { + logger.info { "PromiseUserRegisterHandler 이벤트 수신 ${event.promiseId} , 유저아이디 ${event.userId}" } + + progressHistoryDomainService.initHistory(event.promiseId, event.userId) + } + + @Async + @TransactionalEventListener(classes = [PromiseUserRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) + fun handlePromiseUserRegisterEventInteraction(event: PromiseUserRegisterEvent) { logger.info { "PromiseUserRegisterInteractionInitHandler 이벤트 수신 약속아이디: ${event.promiseId} , 유저아이디: ${event.userId}" } interactionDomainService.initInteraction(event.promiseId, event.userId) }