feat: BAC-30 Implement Jackson Mapping via DTOs (#102)
Reviewed-on: #102 Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
35
knockoutwhistweb/app/dto/GameInfoDTO.scala
Normal file
35
knockoutwhistweb/app/dto/GameInfoDTO.scala
Normal file
@@ -0,0 +1,35 @@
|
||||
package dto
|
||||
|
||||
import dto.subDTO.*
|
||||
import logic.game.GameLobby
|
||||
import model.users.User
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
case class GameInfoDTO(
|
||||
gameId: String,
|
||||
self: Option[PlayerDTO],
|
||||
hand: Option[HandDTO],
|
||||
playerQueue: PlayerQueueDTO,
|
||||
currentTrick: Option[TrickDTO],
|
||||
currentRound: Option[RoundDTO]
|
||||
)
|
||||
|
||||
object GameInfoDTO {
|
||||
|
||||
def apply(lobby: GameLobby, user: User): GameInfoDTO = {
|
||||
val selfPlayer = Try {
|
||||
Some(lobby.getPlayerByUser(user))
|
||||
}.getOrElse(None)
|
||||
|
||||
GameInfoDTO(
|
||||
gameId = lobby.id,
|
||||
self = selfPlayer.map(PlayerDTO(_)),
|
||||
hand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_)),
|
||||
playerQueue = PlayerQueueDTO(lobby.logic),
|
||||
currentTrick = lobby.logic.getCurrentTrick.map(TrickDTO(_)),
|
||||
currentRound = lobby.logic.getCurrentRound.map(RoundDTO(_))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user