blob: 8b653a779fb4c8d5db765c3bc1e832b77aa2066b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
module Model.Category exposing
( Categories
, Category
, CategoryId
, categoriesDecoder
, categoryIdDecoder
, empty
)
import Json.Decode as Decode exposing (Decoder)
import Utils.Json as Json
import Dict exposing (Dict)
type alias Categories = Dict CategoryId Category
type alias CategoryId = Int
type alias Category =
{ name : String
, color : String
}
categoriesDecoder : Decoder Categories
categoriesDecoder =
Json.dictDecoder (Decode.field "id" categoryIdDecoder) <|
Decode.map2
Category
(Decode.field "name" Decode.string)
(Decode.field "color" Decode.string)
categoryIdDecoder : Decoder CategoryId
categoryIdDecoder = Decode.int
empty : Categories
empty = Dict.empty
|