feat(game): Implement return to lobby functionality and enhance dog life handling
This commit is contained in:
@@ -227,7 +227,10 @@ class IngameController @Inject() (
|
||||
val game = podManager.getGame(gameId)
|
||||
game match {
|
||||
case Some(g) => {
|
||||
val cardIdOpt = request.body.asFormUrlEncoded.flatMap(_.get("cardId").flatMap(_.headOption))
|
||||
val jsonBody = request.body.asJson
|
||||
val cardIdOpt: Option[String] = jsonBody.flatMap { jsValue =>
|
||||
(jsValue \ "cardID").asOpt[String]
|
||||
}
|
||||
var optSession: Option[UserSession] = None
|
||||
val result = Try {
|
||||
cardIdOpt match {
|
||||
@@ -343,5 +346,47 @@ class IngameController @Inject() (
|
||||
NotFound("Game not found")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def returnToLobby(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
||||
val game = podManager.getGame(gameId)
|
||||
game match {
|
||||
case Some(g) =>
|
||||
val result = Try {
|
||||
val session = g.getUserSession(request.user.id)
|
||||
g.returnToLobby(session)
|
||||
}
|
||||
if (result.isSuccess) {
|
||||
Ok(Json.obj(
|
||||
"status" -> "success",
|
||||
"redirectUrl" -> routes.IngameController.game(gameId).url
|
||||
))
|
||||
} else {
|
||||
val throwable = result.failed.get
|
||||
throwable match {
|
||||
case _: NotInThisGameException =>
|
||||
BadRequest(Json.obj(
|
||||
"status" -> "failure",
|
||||
"errorMessage" -> throwable.getMessage
|
||||
))
|
||||
case _: IllegalStateException =>
|
||||
BadRequest(Json.obj(
|
||||
"status" -> "failure",
|
||||
"errorMessage" -> throwable.getMessage
|
||||
))
|
||||
case _ =>
|
||||
InternalServerError(Json.obj(
|
||||
"status" -> "failure",
|
||||
"errorMessage" -> throwable.getMessage
|
||||
))
|
||||
}
|
||||
}
|
||||
case None =>
|
||||
NotFound(Json.obj(
|
||||
"status" -> "failure",
|
||||
"errorMessage" -> "Game not found"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user