aboutsummaryrefslogtreecommitdiff
path: root/lib/API.hs
blob: 3fb4c3c15091554e2927d75ef2cc1c08b78f3567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE DerivingStrategies    #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE TypeOperators         #-}
{-# LANGUAGE UndecidableInstances  #-}


module API where

import           Data.Map     (Map)
import           Data.Swagger (Swagger)
import           GTFS
import           Persist
import           Servant      (Application, FromHttpApiData (parseUrlPiece),
                               Server, err401, err404, serve, throwError,
                               type (:>))
import           Servant.API  (Capture, FromHttpApiData, Get, JSON, Post,
                               ReqBody, type (:<|>) ((:<|>)))

type API = "stations" :> Get '[JSON] (Map StationID Station)
  :<|> "timetable" :> Capture "Station ID" StationID :> Get '[JSON] (Map TripID (Trip Deep))
  :<|> "trip" :> Capture "Trip ID" TripID :> Get '[JSON] (Trip Deep)
  -- ingress API (put this behind BasicAuth?)
  -- TODO: perhaps require a first ping for registration?
  :<|> "trip" :> "register" :> Capture "Trip ID" TripID :> Post '[JSON] Token
  -- TODO: perhaps a websocket instead?
  :<|> "trip" :> "ping" :> ReqBody '[JSON] TripPing :> Post '[JSON] ()
  -- debug things
  :<|> "debug" :> "state" :> Get '[JSON] (Map Token [TripPing])
type CompleteAPI = "debug" :> "openapi" :> Get '[JSON] Swagger
  :<|> API