onasty/web/src/Data/Note.elm (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com refactor!: rename "burn before expiration" to "keep before expiration" (#199)..., 9 months ago
olexsmir@gmail.com refactor!: rename "burn before expiration" to "keep before expiration" (#199)..., 9 months ago
| 1 | module Data.Note exposing (CreateResponse, Metadata, Note, decode, decodeCreateResponse, decodeMetadata) |
| 2 | |
| 3 | import Iso8601 |
| 4 | import Json.Decode as D exposing (Decoder) |
| 5 | import Time exposing (Posix) |
| 6 | |
| 7 | |
| 8 | type alias CreateResponse = |
| 9 | { slug : String } |
| 10 | |
| 11 | |
| 12 | decodeCreateResponse : Decoder CreateResponse |
| 13 | decodeCreateResponse = |
| 14 | D.map CreateResponse (D.field "slug" D.string) |
| 15 | |
| 16 | |
| 17 | type alias Note = |
| 18 | { content : String |
| 19 | , readAt : Maybe Posix |
| 20 | , keepBeforeExpiration : Bool |
| 21 | , createdAt : Posix |
| 22 | , expiresAt : Maybe Posix |
| 23 | } |
| 24 | |
| 25 | |
| 26 | decode : Decoder Note |
| 27 | decode = |
| 28 | D.map5 Note |
| 29 | (D.field "content" D.string) |
| 30 | (D.maybe (D.field "read_at" Iso8601.decoder)) |
| 31 | (D.field "keep_before_expiration" D.bool) |
| 32 | (D.field "created_at" Iso8601.decoder) |
| 33 | (D.maybe (D.field "expires_at" Iso8601.decoder)) |
| 34 | |
| 35 | |
| 36 | type alias Metadata = |
| 37 | { createdAt : Posix |
| 38 | , hasPassword : Bool |
| 39 | } |
| 40 | |
| 41 | |
| 42 | decodeMetadata : Decoder Metadata |
| 43 | decodeMetadata = |
| 44 | D.map2 Metadata |
| 45 | (D.field "created_at" Iso8601.decoder) |
| 46 | (D.field "has_password" D.bool) |