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:
22
knockoutwhistweb/app/dto/PlayerQueueDTO.scala
Normal file
22
knockoutwhistweb/app/dto/PlayerQueueDTO.scala
Normal 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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user