Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Api-v0.0.4-2
Browse files Browse the repository at this point in the history
kdomo authored Jul 15, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
romainthomas Romain Thomas
2 parents f4a8f78 + 251afe6 commit 4ecaa6e
Showing 20 changed files with 175 additions and 155 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class PromiseImage(

@PostPersist
fun createImageEvent() {
Events.raise(PromiseImageRegisterEvent(userId, promiseId))
Events.raise(PromiseImageRegisterEvent(userId, promiseId, imageKey))
}

fun validateOwnership(userId: Long) {
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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<Long>,

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<Long>, promiseImageId: Long): Notification {
return Notification(
notificationType = NotificationType.IMAGE,
userId = userId,
targetUserIds = targetUserId,
targetId = promiseImageId,
interactionType = null,
promiseUserType = null,
)
}

fun createForStartSharing(targetUserIds: Set<Long>, promiseId: Long): Notification {
return Notification(
notificationType = NotificationType.START_SHARING,
userId = null,
targetUserIds = targetUserIds,
targetId = promiseId,
interactionType = null,
promiseUserType = null,
)
}

fun createForEndSharing(targetUserIds: Set<Long>, promiseId: Long): Notification {
return Notification(
notificationType = NotificationType.END_SHARING,
userId = null,
targetUserIds = targetUserIds,
targetId = promiseId,
interactionType = null,
promiseUserType = null,
)
}

fun createForTimeOver(targetUserIds: Set<Long>, 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<Long>,
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()
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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<Long>, 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<Long>, promiseId: Long) {
notificationAdapter.save(Notification.createForStartSharing(targetUserIds, promiseId))
fun saveForStartSharing(promiseId: Long, targetUserId: Long) {
notificationAdapter.save(StartSharingNotification(promiseId, targetUserId))
}

@Transactional
fun saveForEndSharing(targetUserIds: Set<Long>, promiseId: Long) {
notificationAdapter.save(Notification.createForEndSharing(targetUserIds, promiseId))
fun saveForEndSharing(promiseId: Long, targetUserId: Long) {
notificationAdapter.save(EndSharingNotification(promiseId, targetUserId))
}

@Transactional
fun saveForTimeOver(targetUserIds: Set<Long>, 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<Long>, 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))
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -5,4 +5,5 @@ import com.depromeet.whatnow.common.aop.event.DomainEvent
class PromiseImageRegisterEvent(
val userId: Long,
val promiseId: Long,
val imageKey: String,
) : DomainEvent()
Original file line number Diff line number Diff line change
@@ -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<String, String> = 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,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> = 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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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!!)
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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!!)
}
}
}
Original file line number Diff line number Diff line change
@@ -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!!)
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4ecaa6e

Please sign in to comment.