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:
20
knockoutwhistweb/app/dto/TrickDTO.scala
Normal file
20
knockoutwhistweb/app/dto/TrickDTO.scala
Normal file
@@ -0,0 +1,20 @@
|
||||
package dto
|
||||
|
||||
import de.knockoutwhist.rounds.Trick
|
||||
import play.api.libs.json.{Json, OFormat}
|
||||
|
||||
case class TrickDTO(cards: Map[PlayerDTO, CardDTO], firstCard: Option[CardDTO], winner: Option[PlayerDTO])
|
||||
|
||||
object TrickDTO {
|
||||
|
||||
implicit val trickFormat: OFormat[TrickDTO] = Json.format[TrickDTO]
|
||||
|
||||
def apply(trick: Trick): TrickDTO = {
|
||||
TrickDTO(
|
||||
cards = trick.cards.map { case (card, player) => PlayerDTO(player) -> CardDTO(card) },
|
||||
firstCard = trick.firstCard.map(card => CardDTO(card)),
|
||||
winner = trick.winner.map(player => PlayerDTO(player))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user