Skip to content

Commit

Permalink
imp: 회원탈퇴 진행시, 그룹 승계 작업 및 제거 작업을 진행
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 20, 2024
1 parent 3b99d67 commit 5c63d0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ interface GroupRepository : JpaRepository<Group, Long> {
fun findByIdAndOwnerUid(id: Long, ownerUid: Long): Group?

fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun findByOwnerUid(ownerUid: Long): Group?
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 5c63d0c

Please sign in to comment.