aboutsummaryrefslogtreecommitdiff
path: root/lib/API.hs
diff options
context:
space:
mode:
authorstuebinm2022-06-16 00:25:15 +0200
committerstuebinm2022-06-16 00:25:15 +0200
commit9e89c93b3b84b5c82c186cff62c33218a0a4d298 (patch)
treef810fc1eacc7b82e82543196257a2e93c5f21a9f /lib/API.hs
parentd418ad82c98ab8dd3d540e910777fa530de350eb (diff)
actually use the database
(at least for a few simple things) Also, more modules!
Diffstat (limited to '')
-rw-r--r--lib/API.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/API.hs b/lib/API.hs
new file mode 100644
index 0000000..3fb4c3c
--- /dev/null
+++ b/lib/API.hs
@@ -0,0 +1,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