Skip to content

Commit

Permalink
Merge pull request #17 from TeamTroublePainter/feature/DRAW-440
Browse files Browse the repository at this point in the history
DRAW-440 게임 시작 시 DB 에서 닉네임 조회
  • Loading branch information
comforest authored Nov 25, 2024
2 parents 7840d83 + 0432666 commit e8fb2cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.xorker.draw.user

import com.xorker.draw.exception.NotFoundUserException
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.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
Expand All @@ -22,9 +24,10 @@ class UserController(
@GetMapping("/api/v1/user")
@NeedLogin
fun getUserDetail(
user: PrincipalUser,
@Parameter(hidden = true) user: PrincipalUser,
): UserDetailResponse {
return userUseCase.getUserDetail(user.userId).toResponse()
val userInfo = userUseCase.getUserDetail(user.userId) ?: throw NotFoundUserException
return userInfo.toResponse()
}

@Operation(summary = "유저 정보 수정")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.xorker.draw.support.logging.logger
import com.xorker.draw.support.logging.registerRequestId
import com.xorker.draw.user.User
import com.xorker.draw.user.UserId
import com.xorker.draw.user.UserUseCase
import com.xorker.draw.websocket.exception.WebSocketExceptionHandler
import com.xorker.draw.websocket.message.request.RequestAction
import com.xorker.draw.websocket.message.request.WebSocketRequest
Expand All @@ -36,6 +37,7 @@ internal abstract class BaseWebSocketHandler(
private val tokenUseCase: TokenUseCase,
private val gameUseCase: MafiaGameUseCase,
private val webSocketExceptionHandler: WebSocketExceptionHandler,
private val userUseCase: UserUseCase,
) : TextWebSocketHandler() {
private val logger = logger()

Expand Down Expand Up @@ -154,7 +156,13 @@ internal abstract class BaseWebSocketHandler(

private fun getUser(session: WebSocketSession): User? {
val userId = getUserId(session) ?: return null
val encodedNickname = session.getHeader(HEADER_NICKNAME) ?: return null
val encodedNickname = session.getHeader(HEADER_NICKNAME)
val user = userUseCase.getUserDetail(userId)

if (user?.name != null) return User(userId, user.name!!)

if (encodedNickname == null) throw InvalidRequestValueException

val nickname = URLDecoder.decode(encodedNickname, StandardCharsets.UTF_8.toString())

return User(userId, nickname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.xorker.draw.auth.token.TokenUseCase
import com.xorker.draw.mafia.MafiaGameUseCase
import com.xorker.draw.mafia.UserConnectionUseCase
import com.xorker.draw.mafia.WaitingQueueUseCase
import com.xorker.draw.user.UserUseCase
import com.xorker.draw.websocket.WebSocketRouter
import com.xorker.draw.websocket.exception.WebSocketExceptionHandler
import com.xorker.draw.websocket.message.request.WebSocketRequest
Expand All @@ -22,6 +23,7 @@ internal class QuickWebSocketHandler(
tokenUseCase: TokenUseCase,
gameUseCase: MafiaGameUseCase,
webSocketExceptionHandler: WebSocketExceptionHandler,
userUseCase: UserUseCase,
private val userConnectionUseCase: UserConnectionUseCase,
private val router: WebSocketRouter,
private val waitingQueueUseCase: WaitingQueueUseCase,
Expand All @@ -32,6 +34,7 @@ internal class QuickWebSocketHandler(
tokenUseCase,
gameUseCase,
webSocketExceptionHandler,
userUseCase,
) {
override fun afterConnect(session: Session) {
waitingQueueUseCase.enqueue(session.user, session.locale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.xorker.draw.auth.token.TokenUseCase
import com.xorker.draw.mafia.MafiaGameUseCase
import com.xorker.draw.mafia.UserConnectionUseCase
import com.xorker.draw.room.RoomId
import com.xorker.draw.user.UserUseCase
import com.xorker.draw.websocket.WebSocketRouter
import com.xorker.draw.websocket.exception.WebSocketExceptionHandler
import com.xorker.draw.websocket.message.request.WebSocketRequest
Expand All @@ -22,6 +23,7 @@ internal class RoomWebSocketHandler(
tokenUseCase: TokenUseCase,
gameUseCase: MafiaGameUseCase,
webSocketExceptionHandler: WebSocketExceptionHandler,
userUseCase: UserUseCase,
private val userConnectionUseCase: UserConnectionUseCase,
private val router: WebSocketRouter,
) : BaseWebSocketHandler(
Expand All @@ -31,6 +33,7 @@ internal class RoomWebSocketHandler(
tokenUseCase,
gameUseCase,
webSocketExceptionHandler,
userUseCase,
) {
override fun afterConnect(session: Session) {
userConnectionUseCase.connectUser(
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/kotlin/com/xorker/draw/user/UserService.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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
override fun getUserDetail(userId: UserId): UserDetail? {
val userInfo = userRepository.getUser(userId) ?: return null

val authInfo = userRepository.getAuthInfo(userId)

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xorker.draw.user

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

fun updateUser(userId: UserId, nickname: String): User
}

0 comments on commit e8fb2cd

Please sign in to comment.