2023-01-10 02:22:46 +00:00
|
|
|
module Deck exposing (..)
|
|
|
|
|
2023-01-10 17:31:31 +00:00
|
|
|
import Card
|
2023-01-10 02:22:46 +00:00
|
|
|
import Json.Decode
|
|
|
|
import Json.Decode.Pipeline as JDP
|
|
|
|
|
|
|
|
|
|
|
|
type alias Deck =
|
|
|
|
{ id : Int
|
|
|
|
, name : String
|
2023-01-10 17:31:31 +00:00
|
|
|
, cards : List Card
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Card =
|
2023-01-11 02:21:33 +00:00
|
|
|
{ card : Card.Card
|
2023-01-10 17:31:31 +00:00
|
|
|
, quantity : Int
|
2023-01-10 02:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decode : Json.Decode.Decoder Deck
|
|
|
|
decode =
|
|
|
|
Json.Decode.succeed Deck
|
|
|
|
|> JDP.required "deck_id" Json.Decode.int
|
|
|
|
|> JDP.required "name" Json.Decode.string
|
2023-01-10 17:31:31 +00:00
|
|
|
|> JDP.required "cards" (Json.Decode.list decodeCard)
|
|
|
|
|
|
|
|
|
|
|
|
decodeCard : Json.Decode.Decoder Card
|
|
|
|
decodeCard =
|
|
|
|
Json.Decode.succeed Card
|
2023-01-11 02:21:33 +00:00
|
|
|
|> JDP.required "card" Card.decode
|
2023-01-10 17:31:31 +00:00
|
|
|
|> JDP.required "quantity" Json.Decode.int
|