From e65336da49be1a225340fa4460d0a27b0c206dae Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Tue, 20 Aug 2024 21:45:51 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20queryParam=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(poc)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ws/config/ReactiveWebSocketConfig.kt | 2 +- .../ReactiveConcurrentUserWebSocketHandler.kt | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/hero/alignlab/ws/config/ReactiveWebSocketConfig.kt b/src/main/kotlin/com/hero/alignlab/ws/config/ReactiveWebSocketConfig.kt index 67ba15e..3388afb 100644 --- a/src/main/kotlin/com/hero/alignlab/ws/config/ReactiveWebSocketConfig.kt +++ b/src/main/kotlin/com/hero/alignlab/ws/config/ReactiveWebSocketConfig.kt @@ -17,7 +17,7 @@ class ReactiveWebSocketConfiguration { ): HandlerMapping { val map = mapOf( /** 접속 유저 처리, 향후 v2로 업데이트 진행 필요 (v1은 poc 개념) */ - "/ws/v1/groups/concurrent-users" to handler + "/ws/v1/groups/{groupId}/users" to handler ) return SimpleUrlHandlerMapping().apply { diff --git a/src/main/kotlin/com/hero/alignlab/ws/handler/ReactiveConcurrentUserWebSocketHandler.kt b/src/main/kotlin/com/hero/alignlab/ws/handler/ReactiveConcurrentUserWebSocketHandler.kt index 23b479e..487efc4 100644 --- a/src/main/kotlin/com/hero/alignlab/ws/handler/ReactiveConcurrentUserWebSocketHandler.kt +++ b/src/main/kotlin/com/hero/alignlab/ws/handler/ReactiveConcurrentUserWebSocketHandler.kt @@ -2,9 +2,12 @@ package com.hero.alignlab.ws.handler import com.hero.alignlab.common.extension.mapper import com.hero.alignlab.domain.auth.application.AuthFacade -import com.hero.alignlab.domain.auth.model.AuthUserToken.Companion.resolve +import com.hero.alignlab.domain.auth.model.AUTH_TOKEN_KEY +import com.hero.alignlab.domain.auth.model.AuthUserToken import com.hero.alignlab.domain.group.application.GroupUserService import com.hero.alignlab.domain.user.application.UserInfoService +import com.hero.alignlab.exception.ErrorCode +import com.hero.alignlab.exception.NotFoundException import com.hero.alignlab.ws.model.ConcurrentMessage import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.CoroutineScope @@ -37,7 +40,20 @@ class ReactiveConcurrentUserWebSocketHandler( private val concurrentUserByMap: ConcurrentMap> = ConcurrentHashMap() override fun handle(session: WebSocketSession): Mono { - val authUserToken = session.handshakeInfo.headers.resolve() + val groupId = session.handshakeInfo.uri.path + .split("/") + .lastOrNull { it.matches(Regex("\\d+")) } + + val queryParams = session.handshakeInfo.uri.query + .split("&") + .associate { + val (key, value) = it.split("=") + key to value + } + + val token = queryParams[AUTH_TOKEN_KEY] ?: throw NotFoundException(ErrorCode.NOT_FOUND_TOKEN_ERROR) + + val authUserToken = AuthUserToken(AUTH_TOKEN_KEY, token) val user = authFacade.resolveAuthUser(authUserToken)