Skip to content

Commit

Permalink
fix: 탈퇴한 사용자 데이터 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Jan 21, 2025
1 parent 7685ae2 commit 357aa56
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 6 deletions.
90 changes: 90 additions & 0 deletions src/main/kotlin/com/hero/alignlab/batch/user/job/UserDeleteJob.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.hero.alignlab.batch.user.job

import com.hero.alignlab.domain.cheer.infrastructure.CheerUpRepository
import com.hero.alignlab.domain.discussion.infrastructure.DiscussionCommentRepository
import com.hero.alignlab.domain.discussion.infrastructure.DiscussionRepository
import com.hero.alignlab.domain.group.infrastructure.GroupRepository
import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository
import com.hero.alignlab.domain.group.infrastructure.GroupUserScoreRepository
import com.hero.alignlab.domain.image.infrastructure.ImageMetadataRepository
import com.hero.alignlab.domain.log.infrastructure.SystemActionLogRepository
import com.hero.alignlab.domain.notification.infrastructure.PoseNotificationRepository
import com.hero.alignlab.domain.pose.infrastructure.*
import com.hero.alignlab.domain.user.infrastructure.CredentialUserInfoRepository
import com.hero.alignlab.domain.user.infrastructure.OAuthUserInfoRepository
import com.hero.alignlab.domain.user.infrastructure.UserInfoRepository
import org.springframework.stereotype.Component

@Component
class UserDeleteJob(
/** user 정보 */
private val userInfoRepository: UserInfoRepository,
private val credentialUserInfoRepository: CredentialUserInfoRepository,
private val oauthUserInfoRepository: OAuthUserInfoRepository,

/** post 정보 */
private val poseLayoutRepository: PoseLayoutRepository,
private val poseLayoutPointRepository: PoseLayoutPointRepository,
private val poseCountRepository: PoseCountRepository,
private val poseKeyPointSnapshotRepository: PoseKeyPointSnapshotRepository,
private val poseSnapshotRepository: PoseSnapshotRepository,

/** noti */
private val poseNotificationRepository: PoseNotificationRepository,

/** syslog */
private val systemActionLogRepository: SystemActionLogRepository,

/** image metadata */
private val imageMetadataRepository: ImageMetadataRepository,

/** group */
private val groupRepository: GroupRepository,
private val groupUserRepository: GroupUserRepository,
private val groupUserScoreRepository: GroupUserScoreRepository,

/** discussion */
private val discussionRepository: DiscussionRepository,
private val discussionCommentRepository: DiscussionCommentRepository,

/** cheer-up */
private val cheerUpRepository: CheerUpRepository,
) {
fun delete() {
/** 전체 유저 정보 조회, uids가 비여있으면 종료시킴 -> *만약 이 조건 풀어버리면, 전부 삭제가 진행.* */
val uids = userInfoRepository.findAll().map { it.id }
.takeIf { it.isNotEmpty() } ?: return

/** 유저 관련 데이터 삭제 */
credentialUserInfoRepository.deleteAllByUidNotIn(uids)
oauthUserInfoRepository.deleteAllByUidNotIn(uids)

/** pose 데이터 삭제 */
val poseLayoutIds = poseLayoutRepository.findAllByUidNotIn(uids).map { it.id }
poseLayoutRepository.deleteAllByUidNotIn(uids)
poseLayoutPointRepository.deleteAllByPoseLayoutIdIn(poseLayoutIds)
poseCountRepository.deleteAllByUidNotIn(uids)
val poseSnapshotIds = poseSnapshotRepository.findAllByUidNotIn(uids)
.map { it.id }
poseSnapshotRepository.deleteAllByUidNotIn(uids)
poseKeyPointSnapshotRepository.deleteAllByPoseSnapshotIdIn(poseSnapshotIds)
poseNotificationRepository.deleteAllByUidNotIn(uids)

/** sys log 삭제 */
systemActionLogRepository.deleteAllByUidNotIn(uids)

/** img 삭제 */
imageMetadataRepository.deleteAllByUidNotIn(uids)

/** group user 삭제 */
groupUserRepository.deleteAllByUidNotIn(uids)
groupUserScoreRepository.deleteAllByUidNotIn(uids)

/** discussion */
discussionRepository.deleteAllByUidNotIn(uids)
discussionCommentRepository.deleteAllByUidNotIn(uids)

/** cheer-up */
cheerUpRepository.deleteAllByUidNotIn(uids)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hero.alignlab.batch.user.scheduler

import com.hero.alignlab.batch.user.job.UserDeleteJob
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class UserDeleteScheduler(
private val userDeleteJob: UserDeleteJob
) {
@Scheduled(cron = "0 0 4 * * *")
fun run() {
CoroutineScope(Dispatchers.IO + Job()).launch {
userDeleteJob.delete()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ interface CheerUpRepository : JpaRepository<CheerUp, Long> {
fun findAllByUidAndCheeredAt(uid: Long, cheeredAt: LocalDate): List<CheerUp>

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ class DevDeleteService(

/** cheer-up */
private val cheerUpRepository: CheerUpRepository,

/** notification */
private val notificationRepository: PoseNotificationRepository,
) {
@Transactional
fun deleteAll(uid: Long) {
Expand Down Expand Up @@ -94,9 +91,6 @@ class DevDeleteService(

/** cheer-up */
cheerUpRepository.deleteAllByUid(uid)

/** notification */
notificationRepository.deleteAllByUid(uid)
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ import org.springframework.transaction.annotation.Transactional
@Repository
interface DiscussionCommentRepository : JpaRepository<DiscussionComment, Long> {
fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface DiscussionRepository : JpaRepository<Discussion, Long> {
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ interface GroupUserRepository : JpaRepository<GroupUser, Long> {
fun deleteAllByUid(uid: Long)

fun findAllByGroupId(groupId: Long): List<GroupUser>

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ interface GroupUserScoreRepository : JpaRepository<GroupUserScore, Long> {
fun deleteAllByModifiedAtBefore(modifiedAt: LocalDateTime)

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface ImageMetadataRepository : JpaRepository<ImageMetadata, Long> {
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface SystemActionLogRepository : JpaRepository<SystemActionLog, Long>, Syst
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ interface PoseNotificationRepository : JpaRepository<PoseNotification, Long> {
fun findByIdAndUid(id: Long, uid: Long): PoseNotification?

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface PoseCountRepository : JpaRepository<PoseCount, Long>, PostCountQReposi
fun findAllByUidInAndDate(uids: List<Long>, date: LocalDate): List<PoseCount>

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ interface PoseLayoutRepository : JpaRepository<PoseLayout, Long> {
fun findAllByUid(uid: Long): List<PoseLayout>

fun deleteAllByUid(uid: Long)

fun deleteAllByUidNotIn(uids: List<Long>)

fun findAllByUidNotIn(uids: List<Long>): List<PoseLayout>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ interface PoseSnapshotRepository : JpaRepository<PoseSnapshot, Long>, PoseSnapsh
fun findAllByUid(uid: Long): List<PoseSnapshot>

fun deleteAllByUid(uid: Long)

fun findAllByUidNotIn(uids: List<Long>): List<PoseSnapshot>

fun deleteAllByUidNotIn(uids: List<Long>)
}

interface PoseSnapshotQRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ interface CredentialUserInfoRepository : JpaRepository<CredentialUserInfo, Long>
fun deleteAllByUid(uid: Long)

fun findAllByUid(uid: Long): List<CredentialUserInfo>

fun deleteAllByUidNotIn(uids: List<Long>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ interface OAuthUserInfoRepository : JpaRepository<OAuthUserInfo, Long> {
fun deleteAllByUid(uid: Long)

fun findAllByUid(uid: Long): List<OAuthUserInfo>

fun deleteAllByUidNotIn(uids: List<Long>)
}

0 comments on commit 357aa56

Please sign in to comment.