From 06484e9ff00dbe2234a8755cc802d1b4cea74715 Mon Sep 17 00:00:00 2001 From: "Rick Su [SSW]" Date: Mon, 19 Feb 2024 07:33:32 +1100 Subject: [PATCH] Add roomId parameter when starting a game (#201) --- .../tw/waterballsa/gaas/application/client/GameService.kt | 1 + .../gaas/application/usecases/StartGameUseCase.kt | 5 ++++- .../gaas/spring/it/controllers/RoomControllerTest.kt | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/application/src/main/kotlin/tw/waterballsa/gaas/application/client/GameService.kt b/application/src/main/kotlin/tw/waterballsa/gaas/application/client/GameService.kt index 68649e5d..d69df9c1 100644 --- a/application/src/main/kotlin/tw/waterballsa/gaas/application/client/GameService.kt +++ b/application/src/main/kotlin/tw/waterballsa/gaas/application/client/GameService.kt @@ -5,6 +5,7 @@ interface GameService { } data class StartGameRequest( + val roomId: String, val players: List, ) { data class GamePlayer( diff --git a/application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/StartGameUseCase.kt b/application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/StartGameUseCase.kt index 738eb7cd..a6f0e921 100644 --- a/application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/StartGameUseCase.kt +++ b/application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/StartGameUseCase.kt @@ -64,8 +64,11 @@ class StartGameUseCase( } private fun Room.startGameByHost(jwtToken: String): StartedGameEvent { + if(roomId == null) { + throw PlatformException(GAME_START_FAILED, "Room Id is null") + } val gameServerHost = game.backEndUrl - val startGameRequest = StartGameRequest(players.map { it.toGamePlayer() }) + val startGameRequest = StartGameRequest(roomId!!.value, players.map { it.toGamePlayer() }) val startGameResponse = gameService.startGame(gameServerHost, jwtToken, startGameRequest) return StartedGameEvent(GAME_STARTED, Data(startGameResponse.url, roomId!!)) diff --git a/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/RoomControllerTest.kt b/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/RoomControllerTest.kt index 14f5d314..fb2d09be 100644 --- a/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/RoomControllerTest.kt +++ b/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/RoomControllerTest.kt @@ -781,7 +781,7 @@ class RoomControllerTest @Autowired constructor( mockMvc.perform( post("/rooms/${room.roomId!!.value}:startGame") .withJwt(toJwt()) - .withJson(StartGameRequest(room.players.map { it.toGamePlayer() })) + .withJson(StartGameRequest(room.roomId!!.value,room.players.map { it.toGamePlayer() })) ) private fun Player.toGamePlayer(): StartGameRequest.GamePlayer =