onasty/web/src/Data/Note.elm (view raw)
| 1 | module Data.Note exposing (CreateResponse, Metadata, Note, decode, decodeCreateResponse, decodeMetadata) |
| 2 | |
| 3 | import Json.Decode as D exposing (Decoder) |
| 4 | |
| 5 | |
| 6 | type alias CreateResponse = |
| 7 | { slug : String } |
| 8 | |
| 9 | |
| 10 | decodeCreateResponse : Decoder CreateResponse |
| 11 | decodeCreateResponse = |
| 12 | D.map CreateResponse |
| 13 | (D.field "slug" D.string) |
| 14 | |
| 15 | |
| 16 | type alias Note = |
| 17 | { content : String |
| 18 | , readAt : Maybe String -- TODO: use Posix |
| 19 | , burnBeforeExpiration : Bool |
| 20 | , createdAt : String -- TODO: use Posix |
| 21 | , expiresAt : Maybe String -- TODO: use Posix |
| 22 | } |
| 23 | |
| 24 | |
| 25 | decode : Decoder Note |
| 26 | decode = |
| 27 | D.map5 Note |
| 28 | (D.field "content" D.string) |
| 29 | (D.maybe (D.field "read_at" D.string)) |
| 30 | (D.field "burn_before_expiration" D.bool) |
| 31 | (D.field "created_at" D.string) |
| 32 | (D.maybe (D.field "expires_at" D.string)) |
| 33 | |
| 34 | |
| 35 | type alias Metadata = |
| 36 | { createdAt : String -- TODO: use Posix |
| 37 | , hasPassword : Bool |
| 38 | } |
| 39 | |
| 40 | |
| 41 | decodeMetadata : Decoder Metadata |
| 42 | decodeMetadata = |
| 43 | D.map2 Metadata |
| 44 | (D.field "created_at" D.string) |
| 45 | (D.field "has_password" D.bool) |