aboutsummaryrefslogtreecommitdiff
path: root/lib/Server
diff options
context:
space:
mode:
authorstuebinm2022-07-03 00:21:25 +0200
committerstuebinm2022-07-03 00:21:25 +0200
commitb4f267ce14c753e952508e6313eec0ff9a99a879 (patch)
tree7baf38a8212b4c5959c5a592a767198187f96490 /lib/Server
parent0197560d9d9ea6ac95146906964fc2408fbf1a31 (diff)
add service monad (with built-in logging)
Diffstat (limited to 'lib/Server')
-rw-r--r--lib/Server/GTFS_RT.hs3
-rw-r--r--lib/Server/Util.hs13
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/Server/GTFS_RT.hs b/lib/Server/GTFS_RT.hs
index e2b23e0..85ea8cd 100644
--- a/lib/Server/GTFS_RT.hs
+++ b/lib/Server/GTFS_RT.hs
@@ -65,6 +65,7 @@ import Servant.API ((:<|>) (..))
import Servant.Server (Handler (Handler),
Server)
+import Server.Util (Service)
uuidUtf8 :: UUID.UUID -> Utf8
uuidUtf8 = Utf8 . fromStrict . UUID.toASCIIBytes
@@ -86,7 +87,7 @@ toStupidDate date = toUtf8
toStupidTime :: UTCTime -> Word64
toStupidTime = fromIntegral . systemSeconds . utcToSystemTime
-gtfsRealtimeServer :: GTFS -> Pool SqlBackend -> Server GtfsRealtimeAPI
+gtfsRealtimeServer :: GTFS -> Pool SqlBackend -> Service GtfsRealtimeAPI
gtfsRealtimeServer gtfs dbpool = handleServiceAlerts :<|> handleTripUpdates :<|> handleVehiclePositions
where handleServiceAlerts = runSql dbpool $ do
-- TODO filter: only select current & future days
diff --git a/lib/Server/Util.hs b/lib/Server/Util.hs
new file mode 100644
index 0000000..45c2477
--- /dev/null
+++ b/lib/Server/Util.hs
@@ -0,0 +1,13 @@
+
+
+-- | mostly the monad the service runs in
+module Server.Util (Service, ServiceM, runService) where
+
+import Control.Monad.Logger (LoggingT, runStderrLoggingT)
+import Servant (Handler, ServerT)
+
+type ServiceM = LoggingT Handler
+type Service api = ServerT api ServiceM
+
+runService :: ServiceM a -> Handler a
+runService = runStderrLoggingT