fix: BAC-29 Implement Mappers for Common Classes (#101)

Reviewed-on: #101
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
2025-12-05 19:24:10 +01:00
committed by Janis
parent 73dbe5826a
commit 270f44cc1f
12 changed files with 202 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
package dto
import de.knockoutwhist.control.GameLogic
import play.api.libs.json.{Json, OFormat}
case class PlayerQueueDTO(currentPlayer: Option[PlayerDTO], queue: Seq[PlayerDTO])
object PlayerQueueDTO {
implicit val queueFormat: OFormat[PlayerQueueDTO] = Json.format[PlayerQueueDTO]
def apply(logic: GameLogic): PlayerQueueDTO = {
val currentPlayerDTO = logic.getCurrentPlayer.map(PlayerDTO(_))
val queueDTO = logic.getPlayerQueue.map(_.duplicate().flatMap(player => Some(PlayerDTO(player))).toSeq)
if (queueDTO.isEmpty) {
PlayerQueueDTO(currentPlayerDTO, Seq.empty)
} else {
PlayerQueueDTO(currentPlayerDTO, queueDTO.get)
}
}
}