all repos

onasty @ d4ca41d

a one-time notes service

onasty/web/src/Data/Note.elm (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
feat(web): add dashboard (#214)..., 8 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
    { slug : String
19
    , content : String
20
    , readAt : Maybe Posix
21
    , keepBeforeExpiration : Bool
22
    , hasPassword : Bool
23
    , createdAt : Posix
24
    , expiresAt : Maybe Posix
25
    }
26
27
28
decode : Decoder Note
29
decode =
30
    D.map7 Note
31
        (D.field "slug" D.string)
32
        (D.field "content" D.string)
33
        (D.maybe (D.field "read_at" Iso8601.decoder))
34
        (D.field "keep_before_expiration" D.bool)
35
        (D.field "has_password" D.bool)
36
        (D.field "created_at" Iso8601.decoder)
37
        (D.maybe (D.field "expires_at" Iso8601.decoder))
38
39
40
type alias Metadata =
41
    { createdAt : Posix
42
    , hasPassword : Bool
43
    }
44
45
46
decodeMetadata : Decoder Metadata
47
decodeMetadata =
48
    D.map2 Metadata
49
        (D.field "created_at" Iso8601.decoder)
50
        (D.field "has_password" D.bool)