feat: Update joinGame endpoint to accept gameId as a path parameter
This commit is contained in:
Submodule knockoutwhistfrontend updated: 352b7fd3ff...92a7bc0586
@@ -55,32 +55,21 @@ class MainMenuController @Inject()(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def joinGame(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
def joinGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
||||||
val jsonBody = request.body.asJson
|
val game = PodManager.getGame(gameId)
|
||||||
val gameId: Option[String] = jsonBody.flatMap { jsValue =>
|
game match {
|
||||||
(jsValue \ "gameId").asOpt[String]
|
case Some(g) =>
|
||||||
}
|
g.addUser(request.user)
|
||||||
if (gameId.isDefined) {
|
Ok(Json.obj(
|
||||||
val game = PodManager.getGame(gameId.get)
|
"status" -> "success",
|
||||||
game match {
|
"redirectUrl" -> routes.IngameController.game(g.id).url,
|
||||||
case Some(g) =>
|
"content" -> IngameController.returnInnerHTML(g, g.logic.getCurrentState, request.user).toString
|
||||||
g.addUser(request.user)
|
))
|
||||||
Ok(Json.obj(
|
case None =>
|
||||||
"status" -> "success",
|
NotFound(Json.obj(
|
||||||
"redirectUrl" -> routes.IngameController.game(g.id).url,
|
"status" -> "failure",
|
||||||
"content" -> IngameController.returnInnerHTML(g, g.logic.getCurrentState, request.user).toString
|
"errorMessage" -> "No Game found"
|
||||||
))
|
))
|
||||||
case None =>
|
|
||||||
NotFound(Json.obj(
|
|
||||||
"status" -> "failure",
|
|
||||||
"errorMessage" -> "No Game found"
|
|
||||||
))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
BadRequest(Json.obj(
|
|
||||||
"status" -> "failure",
|
|
||||||
"errorMessage" -> "Invalid form submission"
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ GET /rules controllers.MainMenuController.rules()
|
|||||||
GET /navSPA/:pType controllers.MainMenuController.navSPA(pType)
|
GET /navSPA/:pType controllers.MainMenuController.navSPA(pType)
|
||||||
|
|
||||||
POST /createGame controllers.MainMenuController.createGame()
|
POST /createGame controllers.MainMenuController.createGame()
|
||||||
POST /joinGame controllers.MainMenuController.joinGame()
|
POST /joinGame/:gameId controllers.MainMenuController.joinGame(gameId: String)
|
||||||
|
|
||||||
# User authentication routes
|
# User authentication routes
|
||||||
POST /login controllers.UserController.login_Post()
|
POST /login controllers.UserController.login_Post()
|
||||||
|
|||||||
Reference in New Issue
Block a user