diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/backend.cabal | 1 | ||||
-rw-r--r-- | backend/lib/ACMS/API/REST/Collection.hs | 31 |
2 files changed, 17 insertions, 15 deletions
diff --git a/backend/backend.cabal b/backend/backend.cabal index ac82e25..c8bff6f 100644 --- a/backend/backend.cabal +++ b/backend/backend.cabal @@ -23,6 +23,7 @@ library aeson, base, bytestring, + common, exceptions, miso, text, diff --git a/backend/lib/ACMS/API/REST/Collection.hs b/backend/lib/ACMS/API/REST/Collection.hs index 7be3269..09f7e32 100644 --- a/backend/lib/ACMS/API/REST/Collection.hs +++ b/backend/lib/ACMS/API/REST/Collection.hs @@ -11,6 +11,7 @@ import Data.Maybe import JavaScript.Web.XMLHttpRequest import Miso.String qualified as J #endif +import Collection import ACMS.API.REST (APIMonad, fetch, restRequest) import Data.Aeson qualified as A import Data.Function ((&)) @@ -18,43 +19,43 @@ import Miso.String (MisoString) import Text.Printf (printf) import Debug.Trace -list :: (APIMonad m) => MisoString -> m [A.Object] +list :: (APIMonad m) => Collection -> m [A.Object] list c = - restRequest (printf "/collection/%s" c) + restRequest (printf "/collection/%s" c.name) & fetch >>= A.throwDecode -read :: (APIMonad m) => MisoString -> MisoString -> m [A.Object] -read c i = - restRequest (printf "/collection/%s/%s" c i) +read :: (APIMonad m) => CollectionItem -> m [A.Object] +read ci = + restRequest (printf "/collection/%s/%s" ci.collection.name ci.itemFileName) & fetch >>= A.throwDecode -update :: (APIMonad m) => MisoString -> MisoString -> A.Object -> m A.Object -update c i o = - restRequest (printf "/collection/%s/%s" c i) +update :: (APIMonad m) => CollectionItem -> A.Object -> m A.Object +update ci o = + restRequest (printf "/collection/%s/%s" ci.collection.name ci.itemFileName) & setRequestMethod "PUT" & setRequestBodyLBS (A.encode o) & fetch >>= A.throwDecode -create :: (APIMonad m) => MisoString -> A.Object -> m A.Object +create :: (APIMonad m) => Collection -> A.Object -> m A.Object create c o = do - restRequest (printf "/collection/%s" c) + restRequest (printf "/collection/%s" c.name) & setRequestMethod "POST" & setRequestBodyLBS (A.encode o) & fetch >>= A.throwDecode -delete :: (APIMonad m) => MisoString -> MisoString -> m [A.Object] -delete c i = - restRequest (printf "/collection/%s/%s" c i) +delete :: (APIMonad m) => CollectionItem -> m [A.Object] +delete ci = + restRequest (printf "/collection/%s/%s" ci.collection.name ci.itemFileName) & setRequestMethod "DELETE" & fetch >>= A.throwDecode -schema :: (APIMonad m) => (A.FromJSON a) => MisoString -> m a +schema :: (APIMonad m) => (A.FromJSON a) => Collection -> m a schema c = - restRequest (printf "/collection/%s/schema" c) + restRequest (printf "/collection/%s/schema" c.name) & fetch >>= A.throwDecode |