Skip to content

Commit

Permalink
fix: queryParam 조건 변경 (poc)
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 20, 2024
1 parent 644c734 commit e65336d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,7 +40,20 @@ class ReactiveConcurrentUserWebSocketHandler(
private val concurrentUserByMap: ConcurrentMap<Long, ConcurrentMap<Long, WebSocketSession>> = ConcurrentHashMap()

override fun handle(session: WebSocketSession): Mono<Void> {
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)

Expand Down

0 comments on commit e65336d

Please sign in to comment.