diff options
author | Kierán Meinhardt <kmein@posteo.de> | 2024-10-13 09:55:20 +0200 |
---|---|---|
committer | Kierán Meinhardt <kmein@posteo.de> | 2024-10-13 09:55:24 +0200 |
commit | 962db630a81a4040902c23c773df3069a48db0a3 (patch) | |
tree | 65c2208cd0fe98aa8979080cb22b84edc35253ef /backend/lib/ACMS/API/REST/Collection.hs | |
parent | 895772f1e76d0cdf12eba5a579ce889d585c9072 (diff) |
move Collection types to common
Diffstat (limited to 'backend/lib/ACMS/API/REST/Collection.hs')
-rw-r--r-- | backend/lib/ACMS/API/REST/Collection.hs | 31 |
1 files changed, 16 insertions, 15 deletions
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 |