diff options
Diffstat (limited to 'backend/src/main/kotlin/org')
-rw-r--r-- | backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt b/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt index 138791fb..5f704357 100644 --- a/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt +++ b/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt @@ -3,7 +3,6 @@ package org.luxons.sevenwonders.validation import org.luxons.sevenwonders.repositories.LobbyRepository import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component -import java.util.regex.Matcher import java.util.regex.Pattern @Component @@ -23,7 +22,7 @@ class DestinationAccessValidator @Autowired constructor(private val lobbyReposit if (!gameMatcher.matches()) { return false // no game reference is always OK } - val gameId = extractId(gameMatcher) + val gameId = gameMatcher.group("id").toLong() return !isUserInLobby(username, gameId) } @@ -32,24 +31,17 @@ class DestinationAccessValidator @Autowired constructor(private val lobbyReposit if (!lobbyMatcher.matches()) { return false // no lobby reference is always OK } - val lobbyId = extractId(lobbyMatcher) + val lobbyId = lobbyMatcher.group("id").toLong() return !isUserInLobby(username, lobbyId) } - private fun isUserInLobby(username: String, lobbyId: Int): Boolean { - val lobby = lobbyRepository.find(lobbyId.toLong()) - return lobby.containsUser(username) - } + private fun isUserInLobby(username: String, lobbyId: Long): Boolean = + lobbyRepository.find(lobbyId).containsUser(username) companion object { private val lobbyDestination = Pattern.compile(".*?/lobby/(?<id>\\d+?)(/.*)?") private val gameDestination = Pattern.compile(".*?/game/(?<id>\\d+?)(/.*)?") - - private fun extractId(matcher: Matcher): Int { - val id = matcher.group("id") - return Integer.parseInt(id) - } } } |