diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-11-05 09:29:02 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-11-05 09:29:02 +0200 |
| commit | f07cf83e6b3e25e5957e4c813b50203f970d4f54 (patch) | |
| tree | 3f8164ab25d9e3d7bdf8e1442611406e2789c085 /src/JsonDecode.elm | |
| parent | b8cdee378647f81bbbbc5aafd4c58b1e15cb0192 (diff) | |
Diffstat (limited to 'src/JsonDecode.elm')
| -rw-r--r-- | src/JsonDecode.elm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/JsonDecode.elm b/src/JsonDecode.elm new file mode 100644 index 0000000..0ec0ba8 --- /dev/null +++ b/src/JsonDecode.elm @@ -0,0 +1,36 @@ +module JsonDecode exposing (..) + +import Json.Decode exposing (..) +import Time +import Types exposing (Author, Post) + + +decodeTime : Decoder Time.Posix +decodeTime = + int + |> andThen + (\ms -> + succeed <| Time.millisToPosix (ms * 1000) + ) + + +postsDecoder : Decoder (List Post) +postsDecoder = + list postDecoder + + +postDecoder : Decoder Post +postDecoder = + map7 Post + (field "id" string) + (field "content" string) + (field "author" + (map2 Author + (field "id" string) + (field "name" string) + ) + ) + (field "createdAt" decodeTime) + (field "likes" int) + (field "userPictureUrl" string) + (maybe <| field "imageUrl" string) |
