diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt index 94a92d2f..8c20c8a1 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt @@ -46,7 +46,7 @@ class Promise( ) : BaseTimeEntity() { @PostPersist fun createPromiseEvent() { - Events.raise(PromiseRegisterEvent(this.id!!)) + Events.raise(PromiseRegisterEvent(this.id!!, this.mainUserId)) } fun updateTitle(title: String) { this.title = title diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseRegisterEvent.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseRegisterEvent.kt index 223ced41..6d795183 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseRegisterEvent.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseRegisterEvent.kt @@ -4,4 +4,5 @@ import com.depromeet.whatnow.common.aop.event.DomainEvent class PromiseRegisterEvent( val promiseId: Long, + val userId: Long, ) : DomainEvent() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt index 4d2fac51..7027c85c 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt @@ -1,3 +1,25 @@ package com.depromeet.whatnow.events.handler -class PromiseRegisterEventHandler +import com.depromeet.whatnow.annotation.Handler +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser +import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService +import com.depromeet.whatnow.events.domainEvent.PromiseRegisterEvent +import org.springframework.scheduling.annotation.Async +import org.springframework.transaction.event.TransactionPhase +import org.springframework.transaction.event.TransactionalEventListener + +@Handler +class PromiseRegisterEventHandler( + val promiseUserDomainService: PromiseUserDomainService, +) { + @Async + @TransactionalEventListener(classes = [PromiseRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) + fun handleRegisterPictureEvent(promiseRegisterEvent: PromiseRegisterEvent) { + // 약속 등록 시 방장의 PromiseUser 생성하기 + val promiseUser = PromiseUser( + promiseId = promiseRegisterEvent.promiseId, + userId = promiseRegisterEvent.userId, + ) + promiseUserDomainService.createPromiseUser(promiseUser) + } +}