aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-03 11:22:10 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-03 11:22:29 +0200
commit74e4a576cf7193ba56f45f26b8597e6533a7d8d1 (patch)
tree53eaa6b489fea1b22b1c19ca32b2fe74bfd25cde /backend
parent8d3fdb08672c89d8657dcd4475acfea56a66b906 (diff)
add querying
Diffstat (limited to 'backend')
-rw-r--r--backend/app/Main.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/backend/app/Main.hs b/backend/app/Main.hs
index e75ce99..82d2d38 100644
--- a/backend/app/Main.hs
+++ b/backend/app/Main.hs
@@ -23,6 +23,7 @@ import Network.HTTP.Types.Status qualified as W
import Network.Wai qualified as W
import Network.Wai.Handler.Warp qualified as W
import Options.Applicative qualified as A
+import Store qualified as Q
import System.Directory (setCurrentDirectory)
import System.FilePath
import Text.Printf (printf)
@@ -117,16 +118,25 @@ main = do
Right (SchemaJson path) -> do
let [c] = filter ((== path) . (.path)) (head repo.commits).collections
respond $ W.responseLBS W.status200 [] (J.encode c.schema)
+ Right Query -> do
+ q <-
+ fromString @Q.Query . LB.toString
+ <$> W.lazyRequestBody req
+ r <- liftIO $ Q.withStore root ref (Q.query q)
+ respond . W.responseLBS W.status200 [] $ J.encode r
(Debug.Trace.traceShowId -> !_) ->
- respond $ W.responseLBS W.status200 [] "OK"
+ respond $ W.responseLBS W.status200 [] "not implemented"
data Route
= SchemaJson String
+ | Query
deriving (Show)
routeP :: P.Parser Route
routeP =
- ( SchemaJson
- <$> (P.string "/" *> P.manyTill P.anyChar (P.string ".schema.json"))
+ ( P.choice
+ [ SchemaJson <$> (P.string "/" *> P.manyTill P.anyChar (P.string ".schema.json")),
+ pure Query <* (P.string "/")
+ ]
)
<* P.endOfInput