blob: 89a5845552b0c65e650958e5e31f728ac9b5ef1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ViewPatterns #-}
module API.Collection where
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
import Data.Text qualified as T
import Process.Shell (Quotable (..), sh)
import Debug.Trace
insert :: T.Text -> T.Text -> A.Object -> IO T.Text
insert
collectionName
fileName
( traceShowId -> AM.insert "$fileName" (A.String fileName) -> traceShowId ->
A.Object -> traceShowId -> contents
) =
{- TODO REST/ CRUD API
[sh|
curl -fsS http://localhost:8081/collections/#{collectionName}/#{filePath} \
--data #{contents}
\|]-}
[sh|
set -efux
curl -fsS http://localhost:8081 \
--data "INSERT "'#{contents}'" INTO #{collectionName}"
|]
-- TODO sh
instance Quotable A.Value where
toString = toString . A.encode
|