tutor/www/src/Deck.elm

34 lines
660 B
Elm
Raw Normal View History

2023-01-10 02:22:46 +00:00
module Deck exposing (..)
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
, cards : List Card
}
type alias Card =
{ card : Card.Card
, 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
|> JDP.required "cards" (Json.Decode.list decodeCard)
decodeCard : Json.Decode.Decoder Card
decodeCard =
Json.Decode.succeed Card
|> JDP.required "card" Card.decode
|> JDP.required "quantity" Json.Decode.int