mi-v1/frontend/src/Mi/SwitchData.elm

65 lines
1.1 KiB
Elm

module Mi.SwitchData exposing
( Switch
, decoder
, frontURL
, idURL
, listURL
, switchURL
)
import Html exposing (..)
import Html.Attributes 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)
switchURL : String
switchURL =
UB.absolute
[ "switches", "switch" ]
[]
idURL : String -> String
idURL id =
UB.absolute
[ "switches", "id", id ]
[]
frontURL : String
frontURL =
UB.absolute
[ "switches", "current" ]
[]
listURL : Int -> Int -> String
listURL limit page =
UB.absolute
[ "switches", "" ]
[ UB.int "limit" limit
, UB.int "page" page
]