diff options
Diffstat (limited to 'sw-server/src')
8 files changed, 19 insertions, 17 deletions
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt index d6573f8f..9530a6b7 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt @@ -57,7 +57,7 @@ class GameBrowserController( fun createGame(@Validated action: CreateGameAction, principal: Principal): LobbyDTO { checkThatUserIsNotInAGame(principal, "cannot create another game") - val player = playerRepository.find(principal.name) + val player = playerRepository.get(principal.name) val lobby = lobbyRepository.create(action.gameName, owner = player) logger.info("Game '{}' ({}) created by {} ({})", lobby.name, lobby.id, player.displayName, player.username) @@ -81,8 +81,8 @@ class GameBrowserController( fun joinGame(@Validated action: JoinGameAction, principal: Principal): LobbyDTO { checkThatUserIsNotInAGame(principal, "cannot join another game") - val lobby = lobbyRepository.find(action.gameId) - val player = playerRepository.find(principal.name) + val lobby = lobbyRepository.get(action.gameId) + val player = playerRepository.get(principal.name) synchronized(lobby) { lobby.addPlayer(player) @@ -93,7 +93,7 @@ class GameBrowserController( } private fun checkThatUserIsNotInAGame(principal: Principal, impossibleActionDescription: String) { - val player = playerRepository.find(principal.name) + val player = playerRepository.get(principal.name) if (player.isInLobby || player.isInGame) { throw UserAlreadyInGameException(player.lobby.name, impossibleActionDescription) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt index 3313d22c..4f948ccf 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt @@ -23,7 +23,7 @@ class GameController( private val lobbyRepository: LobbyRepository, ) { private val Principal.player - get() = playerRepository.find(name) + get() = playerRepository.get(name) /** * Notifies the game that the player is ready to receive his hand. diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt index 557a1714..732b9193 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt @@ -39,7 +39,7 @@ class LobbyController( @Value("\${server.port}") private val serverPort: String, ) { private val Principal.player: Player - get() = playerRepository.find(name) + get() = playerRepository.get(name) /** * Leaves the current lobby. diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt index 06afc78c..e45fb5e9 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt @@ -23,7 +23,7 @@ class LobbyRepository { return lobby } - fun find(lobbyId: Long): Lobby = lobbies[lobbyId] ?: throw LobbyNotFoundException(lobbyId) + fun get(lobbyId: Long): Lobby = lobbies[lobbyId] ?: throw LobbyNotFoundException(lobbyId) fun remove(lobbyId: Long): Lobby = lobbies.remove(lobbyId) ?: throw LobbyNotFoundException(lobbyId) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt index c93b219c..d2d8f967 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt @@ -20,7 +20,9 @@ class PlayerRepository { return p } - fun find(username: String): Player = players[username] ?: throw PlayerNotFoundException(username) + fun find(username: String): Player? = players[username] + + fun get(username: String): Player = find(username) ?: throw PlayerNotFoundException(username) fun remove(username: String): Player = players.remove(username) ?: throw PlayerNotFoundException(username) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt index e680f094..8920a1fd 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt @@ -35,7 +35,7 @@ class DestinationAccessValidator(private val lobbyRepository: LobbyRepository) { } private fun isUserInLobby(username: String, lobbyId: Long): Boolean = - lobbyRepository.find(lobbyId).containsUser(username) + lobbyRepository.get(lobbyId).containsUser(username) companion object { diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt index 8bef7efc..442edac2 100644 --- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt +++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt @@ -41,7 +41,7 @@ class LobbyRepositoryTest { @Test fun find_failsOnUnknownId() { assertFailsWith<LobbyNotFoundException> { - repository.find(123) + repository.get(123) } } @@ -49,8 +49,8 @@ class LobbyRepositoryTest { fun find_returnsTheSameObject() { val lobby1 = repository.create("Test Name 1", Player("owner1", "The Owner")) val lobby2 = repository.create("Test Name 2", Player("owner2", "The Owner")) - assertSame(lobby1, repository.find(lobby1.id)) - assertSame(lobby2, repository.find(lobby2.id)) + assertSame(lobby1, repository.get(lobby1.id)) + assertSame(lobby2, repository.get(lobby2.id)) } @Test @@ -64,10 +64,10 @@ class LobbyRepositoryTest { fun remove_succeeds() { val owner = Player("owner", "The Owner") val lobby1 = repository.create("Test Name 1", owner) - assertNotNull(repository.find(lobby1.id)) + assertNotNull(repository.get(lobby1.id)) repository.remove(lobby1.id) try { - repository.find(lobby1.id) + repository.get(lobby1.id) fail() // the call to find() should have failed } catch (e: LobbyNotFoundException) { // the lobby has been properly removed diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt index fc016903..8e554546 100644 --- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt +++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt @@ -46,7 +46,7 @@ class PlayerRepositoryTest { @Test fun find_failsOnUnknownUsername() { assertFailsWith<PlayerNotFoundException> { - repository.find("anyUsername") + repository.get("anyUsername") } } @@ -54,8 +54,8 @@ class PlayerRepositoryTest { fun find_returnsTheSameObject() { val player1 = repository.createOrUpdate("player1", "Player 1") val player2 = repository.createOrUpdate("player2", "Player 2") - assertSame(player1, repository.find("player1")) - assertSame(player2, repository.find("player2")) + assertSame(player1, repository.get("player1")) + assertSame(player2, repository.get("player2")) } @Test |