feat: BAC-30 Implement Jackson Mapping via DTOs
This commit is contained in:
32
knockoutwhistweb/app/dto/WonInfoDTO.scala
Normal file
32
knockoutwhistweb/app/dto/WonInfoDTO.scala
Normal file
@@ -0,0 +1,32 @@
|
||||
package dto
|
||||
|
||||
import dto.subDTO.PodiumPlayerDTO
|
||||
import logic.game.GameLobby
|
||||
import model.users.User
|
||||
|
||||
case class WonInfoDTO(
|
||||
winner: Option[PodiumPlayerDTO],
|
||||
allPlayers: Seq[PodiumPlayerDTO]
|
||||
)
|
||||
|
||||
object WonInfoDTO {
|
||||
|
||||
def apply(lobby: GameLobby, user: User): WonInfoDTO = {
|
||||
val matchImpl = lobby.logic.getCurrentMatch
|
||||
if (matchImpl.isEmpty) {
|
||||
throw new IllegalStateException("No current match available in game logic")
|
||||
}
|
||||
val allPlayersDTO: Seq[PodiumPlayerDTO] = matchImpl.get.totalplayers.map { player =>
|
||||
PodiumPlayerDTO(lobby.logic, player)
|
||||
}
|
||||
|
||||
val selfPlayerDTO = lobby.getPlayerByUser(user)
|
||||
val winnerDTO = lobby.logic.getWinner
|
||||
|
||||
WonInfoDTO(
|
||||
winner = winnerDTO.map(player => PodiumPlayerDTO(lobby.logic, player)),
|
||||
allPlayers = allPlayersDTO
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user