mi-v1/frontend/src/SwitchData.elm

31 lines
686 B
Elm
Raw Normal View History

2020-01-12 23:31:49 +00:00
module SwitchData exposing (..)
import Iso8601
import Json.Decode exposing (Decoder, field, int, map5, nullable, string)
import Time exposing (Posix)
import Url.Builder as UB
type alias Switch =
{ id : String
, who : String
, started_at : Posix
, ended_at : Maybe Posix
, duration : Int
}
decoder : Decoder Switch
decoder =
map5 Switch
(field "id" string)
(field "who" string)
(field "started_at" Iso8601.decoder)
(field "ended_at" (nullable Iso8601.decoder))
(field "duration" int)
dataURL : Int -> Int -> String
dataURL limit page =
UB.absolute [ "switches" ] [ UB.int "limit" limit, UB.int "page" page ]