From 9e89c93b3b84b5c82c186cff62c33218a0a4d298 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 16 Jun 2022 00:25:15 +0200 Subject: actually use the database (at least for a few simple things) Also, more modules! --- lib/API.hs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/API.hs (limited to 'lib/API.hs') 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 -- cgit v1.2.3