2020-11-10 22:11:05 +00:00
|
|
|
module Mi.Switch exposing (Switch, decoder, frontURL, idURL, listURL, switchURL)
|
2020-11-04 22:16:39 +00:00
|
|
|
|
|
|
|
import Iso8601
|
2020-11-16 15:10:57 +00:00
|
|
|
import Json.Decode exposing (Decoder, field, int, map6, nullable, string)
|
2020-11-10 22:11:05 +00:00
|
|
|
import Time exposing (Posix)
|
2020-11-04 22:16:39 +00:00
|
|
|
import Url.Builder as UB
|
|
|
|
|
2020-11-10 22:11:05 +00:00
|
|
|
|
2020-11-04 22:16:39 +00:00
|
|
|
type alias Switch =
|
|
|
|
{ id : String
|
|
|
|
, who : String
|
|
|
|
, started_at : Posix
|
|
|
|
, ended_at : Maybe Posix
|
|
|
|
, duration : Maybe Int
|
2020-11-16 15:10:57 +00:00
|
|
|
, img_url : String
|
2020-11-04 22:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decoder : Decoder Switch
|
|
|
|
decoder =
|
2020-11-16 15:10:57 +00:00
|
|
|
map6 Switch
|
2020-11-04 22:16:39 +00:00
|
|
|
(field "id" string)
|
|
|
|
(field "who" string)
|
|
|
|
(field "started_at" Iso8601.decoder)
|
|
|
|
(field "ended_at" (nullable Iso8601.decoder))
|
|
|
|
(field "duration" (nullable int))
|
2020-11-16 15:10:57 +00:00
|
|
|
(field "img_url" string)
|
2020-11-04 22:16:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
switchURL : String
|
|
|
|
switchURL =
|
|
|
|
UB.absolute
|
|
|
|
[ "api", "switches", "switch" ]
|
|
|
|
[]
|
|
|
|
|
|
|
|
|
|
|
|
idURL : String -> String
|
|
|
|
idURL id =
|
|
|
|
UB.absolute
|
2020-11-10 22:11:05 +00:00
|
|
|
[ "api", "switches", "id", id ]
|
2020-11-04 22:16:39 +00:00
|
|
|
[]
|
|
|
|
|
|
|
|
|
|
|
|
frontURL : String
|
|
|
|
frontURL =
|
|
|
|
UB.absolute
|
2020-11-10 22:11:05 +00:00
|
|
|
[ "api", "switches", "current" ]
|
2020-11-04 22:16:39 +00:00
|
|
|
[]
|
|
|
|
|
|
|
|
|
|
|
|
listURL : Int -> Int -> String
|
|
|
|
listURL limit page =
|
|
|
|
UB.absolute
|
2020-11-10 22:11:05 +00:00
|
|
|
[ "api", "switches", "" ]
|
2020-11-04 22:16:39 +00:00
|
|
|
[ UB.int "limit" limit
|
|
|
|
, UB.int "page" page
|
2020-11-10 22:11:05 +00:00
|
|
|
]
|