Skip to content

Commit

Permalink
feat: 회원 탈퇴
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 20, 2024
1 parent 171ca6b commit 61377cb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hero.alignlab.domain.auth.application

import com.hero.alignlab.client.kakao.KakaoInfoService
import com.hero.alignlab.client.kakao.model.request.KakaoOAuthUnlinkRequest
import com.hero.alignlab.common.extension.executes
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.auth.model.OAuthProvider
Expand All @@ -12,7 +14,9 @@ import com.hero.alignlab.domain.user.application.OAuthUserInfoService
import com.hero.alignlab.domain.user.application.UserInfoService
import com.hero.alignlab.domain.user.domain.OAuthUserInfo
import com.hero.alignlab.domain.user.domain.UserInfo
import com.hero.alignlab.event.model.WithdrawEvent
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import java.time.LocalDateTime

Expand All @@ -23,6 +27,8 @@ class OAuthFacade(
private val userInfoService: UserInfoService,
private val jwtTokenService: JwtTokenService,
private val txTemplates: TransactionTemplates,
private val kakaoInfoService: KakaoInfoService,
private val publisher: ApplicationEventPublisher,
) {
companion object {
private val TOKEN_EXPIRED_DATE = LocalDateTime.of(2024, 12, 29, 0, 0, 0)
Expand Down Expand Up @@ -84,4 +90,26 @@ class OAuthFacade(
accessToken = token
)
}

suspend fun withdraw(
provider: OAuthProvider,
accessToken: String,
oauthId: String
) {
when (provider) {
OAuthProvider.kakao -> kakaoInfoService.unlink(accessToken, KakaoOAuthUnlinkRequest(targetId = oauthId))
}

val oauthUser = oAuthUserInfoService.findByProviderAndOauthId(provider.toProvider(), oauthId)

if (oauthUser != null) {
/** 유저 정보는 즉시 삭제 */
txTemplates.writer.executes {
oAuthUserInfoService.deleteSync(provider.toProvider(), oauthId)
userInfoService.deleteBySync(oauthUser.uid)

publisher.publishEvent(WithdrawEvent(oauthUser.uid))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hero.alignlab.domain.auth.resource

import com.hero.alignlab.common.extension.wrapCreated
import com.hero.alignlab.common.extension.wrapOk
import com.hero.alignlab.common.extension.wrapVoid
import com.hero.alignlab.domain.auth.application.OAuthFacade
import com.hero.alignlab.domain.auth.model.OAuthProvider
import com.hero.alignlab.domain.auth.model.request.OAuthSignInRequest
Expand Down Expand Up @@ -40,4 +41,16 @@ class OAuthResource(
@PathVariable provider: OAuthProvider,
@RequestBody request: OAuthSignUpRequest,
) = oAuthFacade.signUp(provider, request).wrapCreated()

@Operation(summary = "탈퇴하기")
@DeleteMapping("/api/v1/oauth/{provider}/withdraw")
suspend fun withdraw(
@PathVariable provider: OAuthProvider,
@RequestParam accessToken: String,
@RequestParam oauthId: String,
) = oAuthFacade.withdraw(
provider = provider,
accessToken = accessToken,
oauthId = oauthId
).wrapVoid()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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.infrastructure.GroupRepository
import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository
import com.hero.alignlab.domain.notification.infrastructure.PoseNotificationRepository
import com.hero.alignlab.event.model.WithdrawEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.springframework.stereotype.Component
import org.springframework.transaction.event.TransactionalEventListener

@Component
class WithdrawEventListener(
private val txTemplates: TransactionTemplates,
private val discussionRepository: DiscussionRepository,
private val groupRepository: GroupRepository,
private val groupUserRepository: GroupUserRepository,
private val poseNotificationRepository: PoseNotificationRepository,
private val discussionCommentRepository: DiscussionCommentRepository,
) {
@TransactionalEventListener
fun handle(event: WithdrawEvent) {
CoroutineScope(Dispatchers.IO).launch {
txTemplates.writer.executeWithoutResult {
// TODO: 회원 탈퇴 로직 필요.
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/hero/alignlab/event/model/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ data class SystemActionLogEvent(
}
}
}

data class WithdrawEvent(
val uid: Long,
) : BaseEvent()

0 comments on commit 61377cb

Please sign in to comment.