add querying
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user