Skip to content

Commit

Permalink
feat : PromiseRegisterEventHandler 구현 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBean99 authored and kdomo committed Jun 16, 2023
1 parent 3a06f17 commit f256e94
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.depromeet.whatnow.common.aop.event.DomainEvent

class PromiseRegisterEvent(
val promiseId: Long,
val userId: Long,
) : DomainEvent()
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit f256e94

Please sign in to comment.