Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAW-427 유저 상세 정보 조회 #14

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ internal interface AuthUserJpaRepository : JpaRepository<AuthUserJpaEntity, Long
"and au.platform=:platform ",
)
fun find(platform: AuthPlatform, platformUserId: String): AuthUserJpaEntity?

fun findByUserId(userId: Long): AuthUserJpaEntity?
}
10 changes: 10 additions & 0 deletions adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand All @@ -45,4 +50,9 @@ internal class UserAdapter(
user.name = nickname
return userJpaRepository.save(user).toUser()
}

private fun AuthUserJpaEntity.toDomain(): AuthInfo = AuthInfo(
this.platform,
"[email protected]", // TODO
)
}
11 changes: 11 additions & 0 deletions app/api/src/main/kotlin/com/xorker/draw/user/UserController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P5
userId는 로그인 api에서 일괄적으로 내려주게 되는데, 유저 상세 조회 응답으로 넣은 이유를 알 수 있을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SunwoongH
API 흐름 보다는 API 자체의 역할에 집중했다고 할까요?

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,
)
14 changes: 14 additions & 0 deletions core/src/main/kotlin/com/xorker/draw/user/UserService.kt
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.xorker.draw.user

interface UserUseCase {
fun getUserDetail(userId: UserId): UserDetail

fun updateUser(userId: UserId, nickname: String): User
}
6 changes: 6 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/auth/AuthInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.xorker.draw.auth

data class AuthInfo(
val authPlatform: AuthPlatform,
val email: String,
)
9 changes: 9 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/user/User.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.xorker.draw.user

import com.xorker.draw.auth.AuthPlatform

@JvmInline
value class UserId(val value: Long)

Expand All @@ -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?,
)
3 changes: 3 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/user/UserRepository.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.xorker.draw.user

import com.xorker.draw.auth.AuthInfo
import com.xorker.draw.auth.AuthPlatform

interface UserRepository {
fun getUser(platform: AuthPlatform, platformUserId: String): UserInfo?

fun getUser(userId: UserId): UserInfo?

fun getAuthInfo(userId: UserId): AuthInfo?

fun createUser(platform: AuthPlatform, platformUserId: String, userName: String): UserInfo

fun createUser(userName: String?): UserInfo
Expand Down
Loading