Skip to content

Commit

Permalink
Add roomId parameter when starting a game (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricksu978 authored Feb 18, 2024
1 parent 77d9dea commit 06484e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface GameService {
}

data class StartGameRequest(
val roomId: String,
val players: List<GamePlayer>,
) {
data class GamePlayer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!!))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 06484e9

Please sign in to comment.