From cdcc19a109c9d62156b22ca539a685a5a3de6553 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Mon, 11 Nov 2024 16:28:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?DRAW-443=20feat:=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=8B=9C=20=EC=86=8C=EC=85=9C=20=ED=94=8C=EB=9E=AB=ED=8F=BC=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A0=9C=EA=B1=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xorker/draw/auth/AuthUserJpaRepository.kt | 17 +++++++++++++---- .../auth/token/RefreshTokenJpaRepository.kt | 2 ++ .../kotlin/com/xorker/draw/user/UserAdapter.kt | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt b/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt index 4f73d961..fc32048c 100644 --- a/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt +++ b/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt @@ -1,17 +1,26 @@ package com.xorker.draw.auth import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Modifying import org.springframework.data.jpa.repository.Query +import org.springframework.data.repository.query.Param internal interface AuthUserJpaRepository : JpaRepository { @Query( - "SELECT au FROM AuthUserJpaEntity au " + - "JOIN FETCH au.user " + - "WHERE au.platformUserId = :platformUserId " + + "select au from AuthUserJpaEntity au " + + "join fetch au.user " + + "where au.platformUserId = :platformUserId " + "and au.platform=:platform ", ) fun find(platform: AuthPlatform, platformUserId: String): AuthUserJpaEntity? - fun findByUserId(userId: Long): AuthUserJpaEntity? + fun findByUserId(userId: Long): AuthUserJpaEntity + + @Modifying + @Query( + "delete from AuthUserJpaEntity au " + + "where au.user = :userId", + ) + fun deleteAllByUserId(@Param(value = "userId") userId: Long) } diff --git a/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/token/RefreshTokenJpaRepository.kt b/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/token/RefreshTokenJpaRepository.kt index ffdb12a3..475ac5f2 100644 --- a/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/token/RefreshTokenJpaRepository.kt +++ b/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/token/RefreshTokenJpaRepository.kt @@ -1,7 +1,9 @@ package com.xorker.draw.auth.token import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Modifying internal interface RefreshTokenJpaRepository : JpaRepository { + @Modifying fun deleteByUserId(userId: Long) } diff --git a/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt b/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt index 7d320bec..1346c5ed 100644 --- a/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt +++ b/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt @@ -40,6 +40,9 @@ internal class UserAdapter( override fun withdrawal(userId: UserId) { val user = userJpaRepository.findByIdOrNull(userId.value) ?: throw NotFoundUserException user.withdrawal() + + authUserJpaRepository.deleteAllByUserId(userId.value) + userJpaRepository.save(user) } From 77243be6d5b6c482c4715a4697619643811497cd Mon Sep 17 00:00:00 2001 From: sunwoong Date: Mon, 11 Nov 2024 21:41:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?DRAW-443=20refactor:=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt | 2 +- .../com/xorker/draw/auth/token/RefreshTokenJpaRepository.kt | 2 -- adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt b/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt index fc32048c..f5db9790 100644 --- a/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt +++ b/adapter/rdb/src/main/kotlin/com/xorker/draw/auth/AuthUserJpaRepository.kt @@ -20,7 +20,7 @@ internal interface AuthUserJpaRepository : JpaRepository { - @Modifying fun deleteByUserId(userId: Long) } diff --git a/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt b/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt index 1346c5ed..708b2f69 100644 --- a/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt +++ b/adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt @@ -14,6 +14,7 @@ internal class UserAdapter( private val userJpaRepository: UserJpaRepository, private val authUserJpaRepository: AuthUserJpaRepository, ) : UserRepository { + override fun getUser(platform: AuthPlatform, platformUserId: String): UserInfo? = authUserJpaRepository.find(platform, platformUserId)?.user?.toDomain()