feat: BAC-27 Implement the API Endpoint on the backend

This commit is contained in:
2025-12-03 20:33:20 +01:00
parent 17a200c929
commit e3fc18f199

View File

@@ -2,14 +2,12 @@ package controllers
import auth.{AuthAction, AuthenticatedRequest}
import de.knockoutwhist.control.GameState.{FinishedMatch, InGame, Lobby, MainMenu, SelectTrump, TieBreak}
import de.knockoutwhist.player.AbstractPlayer
import logic.PodManager
import logic.game.GameLobby
import logic.user.SessionManager
import model.users.User
import play.api.libs.json.{JsValue, Json}
import play.api.mvc.{Action, *}
import util.WebUIUtils
import javax.inject.Inject
@@ -97,41 +95,13 @@ class StatusController @Inject()(
"players" -> gameLobby.getUsers.map(p => Json.obj("id" -> p.id, "name" -> p.name, "isSelf" -> (p.id == user.id)))
)
case SelectTrump =>
val findSelector: Option[AbstractPlayer] = gameLobby.logic.getCurrentMatch match {
case Some(matchImpl) =>
if (matchImpl.roundlist.isEmpty) None
else {
matchImpl.roundlist.last.winner match {
case Some(winner) => Some(winner)
case None => None
}
}
case None => None
}
Json.obj(
findSelector match {
case Some(selector) =>
val isSelf = selector.id == user.id
val playerHand = {
val userPlayer = gameLobby.getPlayerByUser(user)
val handOpt = userPlayer.currentHand()
handOpt match {
case Some(hand) =>
WebUIUtils.handToJson(hand)
case None => Json.arr()
}
}
Json.obj(
"selector" -> selector.name,
"isSelf" -> isSelf,
"hand" -> playerHand
)
case None => Json.obj(
"error" -> "No winner found. Please try again later."
)
}
)
case MainMenu =>
Json.obj()
Json.obj(
)
case InGame =>
Json.obj(
@@ -143,7 +113,7 @@ class StatusController @Inject()(
case FinishedMatch =>
Json.obj(
)
)
}
}