diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-10-11 14:17:33 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-10-11 14:17:33 +0200 |
commit | 35bf45a81da20d782a8a654703eca14543e25def (patch) | |
tree | 920d7d884786b900ba194d1433bc010b94f4e46c /cli/app/API/Collection.hs | |
parent | 939cc3e115f5f7b06b09b46c4519502027e25d0d (diff) |
add CLI draft
Diffstat (limited to 'cli/app/API/Collection.hs')
-rw-r--r-- | cli/app/API/Collection.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cli/app/API/Collection.hs b/cli/app/API/Collection.hs new file mode 100644 index 0000000..89a5845 --- /dev/null +++ b/cli/app/API/Collection.hs @@ -0,0 +1,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 |