Skip to content

Commit 5c63d0c

Browse files
committed
imp: 회원탈퇴 진행시, 그룹 승계 작업 및 제거 작업을 진행
1 parent 3b99d67 commit 5c63d0c

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ class GroupFacade(
5858
}
5959

6060
suspend fun withdraw(user: AuthUser, groupId: Long) {
61+
withdraw(groupId, user.uid)
62+
}
63+
64+
suspend fun withdraw(groupId: Long, uid: Long) {
6165
val group = groupService.findByIdOrThrow(groupId)
6266

63-
when (group.ownerUid == user.uid) {
67+
when (group.ownerUid == uid) {
6468
true -> withdrawGroupOwner(group)
65-
false -> withdrawGroupUser(groupId, user)
69+
false -> withdrawGroupUser(groupId, uid)
6670
}
6771
}
6872

@@ -85,9 +89,9 @@ class GroupFacade(
8589
}
8690
}
8791

88-
private suspend fun withdrawGroupUser(groupId: Long, user: AuthUser) {
92+
private suspend fun withdrawGroupUser(groupId: Long, uid: Long) {
8993
txTemplates.writer.executesOrNull {
90-
groupUserService.deleteBySync(groupId, user.uid)
94+
groupUserService.deleteBySync(groupId, uid)
9195
}
9296
}
9397

src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ interface GroupRepository : JpaRepository<Group, Long> {
1414
fun findByIdAndOwnerUid(id: Long, ownerUid: Long): Group?
1515

1616
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long
17+
18+
fun findByOwnerUid(ownerUid: Long): Group?
1719
}

src/main/kotlin/com/hero/alignlab/event/listener/WithdrawEventListener.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.hero.alignlab.event.listener
22

3-
import com.hero.alignlab.config.database.TransactionTemplates
4-
import com.hero.alignlab.domain.discussion.infrastructure.DiscussionCommentRepository
5-
import com.hero.alignlab.domain.discussion.infrastructure.DiscussionRepository
3+
import com.hero.alignlab.domain.group.application.GroupFacade
64
import com.hero.alignlab.domain.group.infrastructure.GroupRepository
7-
import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository
85
import com.hero.alignlab.domain.notification.infrastructure.PoseNotificationRepository
6+
import com.hero.alignlab.domain.pose.infrastructure.*
97
import com.hero.alignlab.event.model.WithdrawEvent
108
import kotlinx.coroutines.CoroutineScope
119
import kotlinx.coroutines.Dispatchers
@@ -15,18 +13,29 @@ import org.springframework.transaction.event.TransactionalEventListener
1513

1614
@Component
1715
class WithdrawEventListener(
18-
private val txTemplates: TransactionTemplates,
19-
private val discussionRepository: DiscussionRepository,
16+
/** 탈퇴 회원이 그룹장인 경우 승계 작업 필요. */
17+
private val groupFacade: GroupFacade,
2018
private val groupRepository: GroupRepository,
21-
private val groupUserRepository: GroupUserRepository,
19+
20+
/** 자세 데이터, 탈퇴회원이 있더라도 문제 없음. */
21+
private val poseCountRepository: PoseCountRepository,
22+
private val poseSnapshotRepository: PoseSnapshotRepository,
23+
private val poseKeyPointSnapshotRepository: PoseKeyPointSnapshotRepository,
24+
private val poseLayoutRepository: PoseLayoutRepository,
25+
private val poseLayoutPointRepository: PoseLayoutPointRepository,
2226
private val poseNotificationRepository: PoseNotificationRepository,
23-
private val discussionCommentRepository: DiscussionCommentRepository,
2427
) {
28+
/**
29+
* 현상황에서 그룹 승계 작업만 원활히 진행되면, 그외 데이터의 경우 탈퇴로 인한 문제는 발생하지 않는다.
30+
*/
2531
@TransactionalEventListener
2632
fun handle(event: WithdrawEvent) {
33+
/** 그룹 승계 및 탈퇴 */
2734
CoroutineScope(Dispatchers.IO).launch {
28-
txTemplates.writer.executeWithoutResult {
29-
// TODO: 회원 탈퇴 로직 필요.
35+
val group = groupRepository.findByOwnerUid(event.uid)
36+
37+
if (group != null) {
38+
groupFacade.withdraw(group.id, event.uid)
3039
}
3140
}
3241
}

0 commit comments

Comments
 (0)