From 5c63d0ce3a6f69cfd006af1be41d4cd27e67970c Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Wed, 21 Aug 2024 08:57:37 +0900 Subject: [PATCH] =?UTF-8?q?imp:=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=EC=8B=9C,=20=EA=B7=B8=EB=A3=B9=20=EC=8A=B9?= =?UTF-8?q?=EA=B3=84=20=EC=9E=91=EC=97=85=20=EB=B0=8F=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=20=EC=9E=91=EC=97=85=EC=9D=84=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/group/application/GroupFacade.kt | 12 +++++--- .../group/infrastructure/GroupRepository.kt | 2 ++ .../event/listener/WithdrawEventListener.kt | 29 ++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt index a6fbf12..b1df280 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt @@ -58,11 +58,15 @@ class GroupFacade( } suspend fun withdraw(user: AuthUser, groupId: Long) { + withdraw(groupId, user.uid) + } + + suspend fun withdraw(groupId: Long, uid: Long) { val group = groupService.findByIdOrThrow(groupId) - when (group.ownerUid == user.uid) { + when (group.ownerUid == uid) { true -> withdrawGroupOwner(group) - false -> withdrawGroupUser(groupId, user) + false -> withdrawGroupUser(groupId, uid) } } @@ -85,9 +89,9 @@ class GroupFacade( } } - private suspend fun withdrawGroupUser(groupId: Long, user: AuthUser) { + private suspend fun withdrawGroupUser(groupId: Long, uid: Long) { txTemplates.writer.executesOrNull { - groupUserService.deleteBySync(groupId, user.uid) + groupUserService.deleteBySync(groupId, uid) } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupRepository.kt b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupRepository.kt index 9a8d13d..700835a 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupRepository.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupRepository.kt @@ -14,4 +14,6 @@ interface GroupRepository : JpaRepository { fun findByIdAndOwnerUid(id: Long, ownerUid: Long): Group? fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long + + fun findByOwnerUid(ownerUid: Long): Group? } diff --git a/src/main/kotlin/com/hero/alignlab/event/listener/WithdrawEventListener.kt b/src/main/kotlin/com/hero/alignlab/event/listener/WithdrawEventListener.kt index 5b359dd..bee7e65 100644 --- a/src/main/kotlin/com/hero/alignlab/event/listener/WithdrawEventListener.kt +++ b/src/main/kotlin/com/hero/alignlab/event/listener/WithdrawEventListener.kt @@ -1,11 +1,9 @@ package com.hero.alignlab.event.listener -import com.hero.alignlab.config.database.TransactionTemplates -import com.hero.alignlab.domain.discussion.infrastructure.DiscussionCommentRepository -import com.hero.alignlab.domain.discussion.infrastructure.DiscussionRepository +import com.hero.alignlab.domain.group.application.GroupFacade import com.hero.alignlab.domain.group.infrastructure.GroupRepository -import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository import com.hero.alignlab.domain.notification.infrastructure.PoseNotificationRepository +import com.hero.alignlab.domain.pose.infrastructure.* import com.hero.alignlab.event.model.WithdrawEvent import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -15,18 +13,29 @@ import org.springframework.transaction.event.TransactionalEventListener @Component class WithdrawEventListener( - private val txTemplates: TransactionTemplates, - private val discussionRepository: DiscussionRepository, + /** 탈퇴 회원이 그룹장인 경우 승계 작업 필요. */ + private val groupFacade: GroupFacade, private val groupRepository: GroupRepository, - private val groupUserRepository: GroupUserRepository, + + /** 자세 데이터, 탈퇴회원이 있더라도 문제 없음. */ + private val poseCountRepository: PoseCountRepository, + private val poseSnapshotRepository: PoseSnapshotRepository, + private val poseKeyPointSnapshotRepository: PoseKeyPointSnapshotRepository, + private val poseLayoutRepository: PoseLayoutRepository, + private val poseLayoutPointRepository: PoseLayoutPointRepository, private val poseNotificationRepository: PoseNotificationRepository, - private val discussionCommentRepository: DiscussionCommentRepository, ) { + /** + * 현상황에서 그룹 승계 작업만 원활히 진행되면, 그외 데이터의 경우 탈퇴로 인한 문제는 발생하지 않는다. + */ @TransactionalEventListener fun handle(event: WithdrawEvent) { + /** 그룹 승계 및 탈퇴 */ CoroutineScope(Dispatchers.IO).launch { - txTemplates.writer.executeWithoutResult { - // TODO: 회원 탈퇴 로직 필요. + val group = groupRepository.findByOwnerUid(event.uid) + + if (group != null) { + groupFacade.withdraw(group.id, event.uid) } } }