From aa1a9bbdae3b071a499bb136d8e1161bb950b4e3 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Thu, 7 Nov 2024 18:27:40 +0900 Subject: [PATCH 1/4] =?UTF-8?q?DRAW-440=20feat:=20=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EC=8B=9C=20DB=20=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/xorker/draw/user/UserController.kt | 7 +++++-- .../xorker/draw/websocket/handler/BaseWebSocketHandler.kt | 5 ++++- core/src/main/kotlin/com/xorker/draw/user/UserService.kt | 4 ++-- core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) 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 a07688df..555ae88e 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 @@ -1,5 +1,6 @@ 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 @@ -7,6 +8,7 @@ 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 @@ -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 = "유저 정보 수정") diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt index 0c40e8f5..5a4fbc53 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt @@ -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 @@ -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() @@ -155,7 +157,8 @@ 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 nickname = URLDecoder.decode(encodedNickname, StandardCharsets.UTF_8.toString()) + val user = userUseCase.getUserDetail(userId) + val nickname = user?.name ?: URLDecoder.decode(encodedNickname, StandardCharsets.UTF_8.toString()) return User(userId, nickname) } 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 d952a9ba..f07cb2ab 100644 --- a/core/src/main/kotlin/com/xorker/draw/user/UserService.kt +++ b/core/src/main/kotlin/com/xorker/draw/user/UserService.kt @@ -7,8 +7,8 @@ import org.springframework.stereotype.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) 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 dca9ba13..6c244aa7 100644 --- a/core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt +++ b/core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt @@ -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 } From 0f8abff8052765a7ead3432daa04027557d59a92 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Mon, 11 Nov 2024 19:31:22 +0900 Subject: [PATCH 2/4] DRAW-440 style: ktlint --- core/src/main/kotlin/com/xorker/draw/user/UserService.kt | 1 - 1 file changed, 1 deletion(-) 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 f07cb2ab..ffd8b077 100644 --- a/core/src/main/kotlin/com/xorker/draw/user/UserService.kt +++ b/core/src/main/kotlin/com/xorker/draw/user/UserService.kt @@ -1,6 +1,5 @@ package com.xorker.draw.user -import com.xorker.draw.exception.NotFoundUserException import org.springframework.stereotype.Service @Service From 408bd4477ab3b8bc3412b410d96914752e181030 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Mon, 11 Nov 2024 19:41:52 +0900 Subject: [PATCH 3/4] =?UTF-8?q?DRAW-440=20fix:=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xorker/draw/websocket/handler/QuickWebSocketHandler.kt | 3 +++ .../com/xorker/draw/websocket/handler/RoomWebSocketHandler.kt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/QuickWebSocketHandler.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/QuickWebSocketHandler.kt index 924535f4..f3565e71 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/QuickWebSocketHandler.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/QuickWebSocketHandler.kt @@ -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 @@ -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, @@ -32,6 +34,7 @@ internal class QuickWebSocketHandler( tokenUseCase, gameUseCase, webSocketExceptionHandler, + userUseCase, ) { override fun afterConnect(session: Session) { waitingQueueUseCase.enqueue(session.user, session.locale) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/RoomWebSocketHandler.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/RoomWebSocketHandler.kt index f4a64e7e..08c28819 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/RoomWebSocketHandler.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/RoomWebSocketHandler.kt @@ -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 @@ -22,6 +23,7 @@ internal class RoomWebSocketHandler( tokenUseCase: TokenUseCase, gameUseCase: MafiaGameUseCase, webSocketExceptionHandler: WebSocketExceptionHandler, + userUseCase: UserUseCase, private val userConnectionUseCase: UserConnectionUseCase, private val router: WebSocketRouter, ) : BaseWebSocketHandler( @@ -31,6 +33,7 @@ internal class RoomWebSocketHandler( tokenUseCase, gameUseCase, webSocketExceptionHandler, + userUseCase, ) { override fun afterConnect(session: Session) { userConnectionUseCase.connectUser( From 0432666566586446b919fbb2f2f46d1e3e279853 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Sun, 17 Nov 2024 16:24:15 +0900 Subject: [PATCH 4/4] =?UTF-8?q?DRAW-440=20fix:=20=EC=9B=B9=EC=86=8C?= =?UTF-8?q?=EC=BC=93=20=EC=97=B0=EA=B2=B0=20=EC=8B=9C=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=97=86=EC=9D=84=EB=95=8C=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../draw/websocket/handler/BaseWebSocketHandler.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt index 5a4fbc53..cb8504d6 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/handler/BaseWebSocketHandler.kt @@ -156,9 +156,14 @@ 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) - val nickname = user?.name ?: URLDecoder.decode(encodedNickname, StandardCharsets.UTF_8.toString()) + + 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) }