From 31bd63db3947677f59f1ae5a99ff904129c5eb24 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Thu, 24 Oct 2024 23:37:58 +0900 Subject: [PATCH] =?UTF-8?q?DRAW-427=20feat:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xorker/draw/auth/AuthUserJpaRepository.kt | 32 ++++++++++--------- .../com/xorker/draw/user/UserAdapter.kt | 10 ++++++ .../com/xorker/draw/user/UserController.kt | 11 +++++++ .../draw/user/dto/UserDetailResponse.kt | 22 +++++++++++++ .../com/xorker/draw/user/UserService.kt | 14 ++++++++ .../com/xorker/draw/user/UserUseCase.kt | 2 ++ .../kotlin/com/xorker/draw/auth/AuthInfo.kt | 6 ++++ .../main/kotlin/com/xorker/draw/user/User.kt | 9 ++++++ .../com/xorker/draw/user/UserRepository.kt | 3 ++ 9 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 app/api/src/main/kotlin/com/xorker/draw/user/dto/UserDetailResponse.kt create mode 100644 domain/src/main/kotlin/com/xorker/draw/auth/AuthInfo.kt 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 383afbf3..972d83b4 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,15 +1,17 @@ -package com.xorker.draw.auth - -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.Query - -internal interface AuthUserJpaRepository : JpaRepository { - - @Query( - "SELECT au FROM AuthUserJpaEntity au " + - "JOIN FETCH au.user " + - "WHERE au.platformUserId = :platformUserId " + - "and au.platform=:platform ", - ) - fun find(platform: AuthPlatform, platformUserId: String): AuthUserJpaEntity? -} +package com.xorker.draw.auth + +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query + +internal interface AuthUserJpaRepository : JpaRepository { + + @Query( + "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? +} 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 e82168d4..ecf26d69 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 @@ -1,5 +1,6 @@ package com.xorker.draw.user +import com.xorker.draw.auth.AuthInfo import com.xorker.draw.auth.AuthPlatform import com.xorker.draw.auth.AuthUserJpaEntity import com.xorker.draw.auth.AuthUserJpaRepository @@ -19,6 +20,10 @@ internal class UserAdapter( override fun getUser(userId: UserId): UserInfo? = userJpaRepository.findByIdOrNull(userId.value)?.toDomain() + override fun getAuthInfo(userId: UserId): AuthInfo? { + return authUserJpaRepository.findByUserId(userId.value)?.toDomain() + } + override fun createUser(platform: AuthPlatform, platformUserId: String, userName: String): UserInfo { val user = UserJpaEntity() val authUser = authUserJpaRepository.save(AuthUserJpaEntity.of(platform, platformUserId, user)) @@ -45,4 +50,9 @@ internal class UserAdapter( user.name = nickname return userJpaRepository.save(user).toUser() } + + private fun AuthUserJpaEntity.toDomain(): AuthInfo = AuthInfo( + this.platform, + "sample@sample.com", // TODO + ) } diff --git a/app/api/src/main/kotlin/com/xorker/draw/user/UserController.kt b/app/api/src/main/kotlin/com/xorker/draw/user/UserController.kt index ea0d9dce..2051b921 100644 --- a/app/api/src/main/kotlin/com/xorker/draw/user/UserController.kt +++ b/app/api/src/main/kotlin/com/xorker/draw/user/UserController.kt @@ -3,10 +3,12 @@ package com.xorker.draw.user import com.xorker.draw.support.auth.NeedLogin import com.xorker.draw.support.auth.PrincipalUser import com.xorker.draw.user.dto.UpdateUserRequest +import com.xorker.draw.user.dto.UserDetailResponse import com.xorker.draw.user.dto.UserResponse import com.xorker.draw.user.dto.toResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController @@ -16,6 +18,15 @@ import org.springframework.web.bind.annotation.RestController class UserController( private val userUseCase: UserUseCase, ) { + @Operation(summary = "유저 상세 정보 조회") + @GetMapping("/api/v1/user") + @NeedLogin + fun getUserDetail( + user: PrincipalUser, + ): UserDetailResponse { + return userUseCase.getUserDetail(user.userId).toResponse() + } + @Operation(summary = "유저 정보 수정") @PatchMapping("/api/v1/user") @NeedLogin diff --git a/app/api/src/main/kotlin/com/xorker/draw/user/dto/UserDetailResponse.kt b/app/api/src/main/kotlin/com/xorker/draw/user/dto/UserDetailResponse.kt new file mode 100644 index 00000000..0fc1cb2c --- /dev/null +++ b/app/api/src/main/kotlin/com/xorker/draw/user/dto/UserDetailResponse.kt @@ -0,0 +1,22 @@ +package com.xorker.draw.user.dto + +import com.xorker.draw.auth.AuthPlatform +import com.xorker.draw.user.UserDetail +import com.xorker.draw.user.UserId +import io.swagger.v3.oas.annotations.media.Schema + +data class UserDetailResponse( + val id: UserId, + val nickname: String?, + + @Schema(description = "null 일 경우 게스트") + val authPlatform: AuthPlatform?, + val email: String?, +) + +fun UserDetail.toResponse(): UserDetailResponse = UserDetailResponse( + id = this.id, + nickname = this.name, + authPlatform = this.authPlatform, + email = this.email, +) diff --git a/core/src/main/kotlin/com/xorker/draw/user/UserService.kt b/core/src/main/kotlin/com/xorker/draw/user/UserService.kt index 98a0e779..9f3c0bdc 100644 --- a/core/src/main/kotlin/com/xorker/draw/user/UserService.kt +++ b/core/src/main/kotlin/com/xorker/draw/user/UserService.kt @@ -1,11 +1,25 @@ package com.xorker.draw.user +import com.xorker.draw.exception.NotFoundUserException import org.springframework.stereotype.Service @Service internal class UserService( private val userRepository: UserRepository, ) : UserUseCase { + override fun getUserDetail(userId: UserId): UserDetail { + val userInfo = userRepository.getUser(userId) ?: throw NotFoundUserException + + val authInfo = userRepository.getAuthInfo(userId) + + return UserDetail( + userId, + userInfo.name, + authInfo?.email, + authInfo?.authPlatform, + ) + } + override fun updateUser(userId: UserId, nickname: String): User { return userRepository.updateNickname(userId, nickname) } diff --git a/core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt b/core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt index 46b69e11..24dbdd38 100644 --- a/core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt +++ b/core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt @@ -1,5 +1,7 @@ package com.xorker.draw.user interface UserUseCase { + fun getUserDetail(userId: UserId): UserDetail + fun updateUser(userId: UserId, nickname: String): User } diff --git a/domain/src/main/kotlin/com/xorker/draw/auth/AuthInfo.kt b/domain/src/main/kotlin/com/xorker/draw/auth/AuthInfo.kt new file mode 100644 index 00000000..3ad1bc98 --- /dev/null +++ b/domain/src/main/kotlin/com/xorker/draw/auth/AuthInfo.kt @@ -0,0 +1,6 @@ +package com.xorker.draw.auth + +data class AuthInfo( + val authPlatform: AuthPlatform, + val email: String, +) diff --git a/domain/src/main/kotlin/com/xorker/draw/user/User.kt b/domain/src/main/kotlin/com/xorker/draw/user/User.kt index c592c27c..c9796439 100644 --- a/domain/src/main/kotlin/com/xorker/draw/user/User.kt +++ b/domain/src/main/kotlin/com/xorker/draw/user/User.kt @@ -1,5 +1,7 @@ package com.xorker.draw.user +import com.xorker.draw.auth.AuthPlatform + @JvmInline value class UserId(val value: Long) @@ -12,3 +14,10 @@ data class UserInfo( val id: UserId, val name: String?, ) + +data class UserDetail( + val id: UserId, + val name: String?, + val email: String?, + val authPlatform: AuthPlatform?, +) diff --git a/domain/src/main/kotlin/com/xorker/draw/user/UserRepository.kt b/domain/src/main/kotlin/com/xorker/draw/user/UserRepository.kt index 1ccdba9e..75076a22 100644 --- a/domain/src/main/kotlin/com/xorker/draw/user/UserRepository.kt +++ b/domain/src/main/kotlin/com/xorker/draw/user/UserRepository.kt @@ -1,5 +1,6 @@ package com.xorker.draw.user +import com.xorker.draw.auth.AuthInfo import com.xorker.draw.auth.AuthPlatform interface UserRepository { @@ -7,6 +8,8 @@ interface UserRepository { fun getUser(userId: UserId): UserInfo? + fun getAuthInfo(userId: UserId): AuthInfo? + fun createUser(platform: AuthPlatform, platformUserId: String, userName: String): UserInfo fun createUser(userName: String?): UserInfo