diff options
Diffstat (limited to 'backend/lib/ACMS/API/REST')
-rw-r--r-- | backend/lib/ACMS/API/REST/Collection.hs | 51 | ||||
-rw-r--r-- | backend/lib/ACMS/API/REST/Collection/Paginated.hs | 33 |
2 files changed, 0 insertions, 84 deletions
diff --git a/backend/lib/ACMS/API/REST/Collection.hs b/backend/lib/ACMS/API/REST/Collection.hs deleted file mode 100644 index 7de1909..0000000 --- a/backend/lib/ACMS/API/REST/Collection.hs +++ /dev/null @@ -1,51 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module ACMS.API.REST.Collection where - -import ACMS.API.Fetch -import ACMS.API.REST (restRequest) -import Collection -import Data.Aeson qualified as A -import Data.Function ((&)) -import Text.Printf (printf) - -list :: (APIMonad m) => Collection -> m [A.Object] -list c = - restRequest (printf "/collection/%s" c.name) - & fetch - >>= A.throwDecode - -read :: (APIMonad m) => CollectionItem -> m (Maybe A.Object) -read ci = - restRequest (printf "/collection/%s/%s" ci.collection.name ci.itemFileName) - & fetch - >>= A.throwDecode - -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) => Collection -> A.Object -> m A.Object -create c o = do - restRequest (printf "/collection/%s" c.name) - & setRequestMethod "POST" - & setRequestBodyLBS (A.encode o) - & fetch - >>= A.throwDecode - -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) => Collection -> m a -schema c = - restRequest (printf "/collection/%s/schema" c.name) - & fetch - >>= A.throwDecode diff --git a/backend/lib/ACMS/API/REST/Collection/Paginated.hs b/backend/lib/ACMS/API/REST/Collection/Paginated.hs deleted file mode 100644 index 159754a..0000000 --- a/backend/lib/ACMS/API/REST/Collection/Paginated.hs +++ /dev/null @@ -1,33 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} - -module ACMS.API.REST.Collection.Paginated where - -import ACMS.API.Fetch -import ACMS.API.REST (restRequest) -import Collection -import Data.Aeson qualified as A -import Data.Function ((&)) -import GHC.Generics (Generic) -import Text.Printf (printf) - -data Pagination = Pagination - { limit :: Int, - offset :: Int - } - -data Paginated a = Paginated - { count :: Int, - data_ :: [a] - } - deriving (Eq, Show, Generic) - -instance (A.FromJSON a) => A.FromJSON (Paginated a) - -instance (A.ToJSON a) => A.ToJSON (Paginated a) - -list :: (APIMonad m) => Pagination -> Collection -> m (Paginated A.Object) -list p c = - restRequest (printf "/collection/%s/paginated/%d/%d" c.name p.limit p.offset) - & fetch - >>= A.throwDecode |