Commit a3861819 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API] splitting the routes (needs a code review of the api)

parent 1d2d97f9
Pipeline #1668 passed with stage
in 22 minutes
......@@ -262,6 +262,7 @@ setListNgrams listId ngramsType ns = do
. something
)
)
printDebug "List modified" NodeList
saveRepo
......
......@@ -56,20 +56,59 @@ import Gargantext.Database.Types (Indexed(..))
import Gargantext.Prelude
------------------------------------------------------------------------
-- | TODO refactor
type API = Get '[JSON, HTML] (Headers '[Header "Content-Disposition" Text] NgramsList)
-- :<|> ReqBody '[JSON] NgramsList :> Post '[JSON] Bool
:<|> PostAPI
:<|> CSVPostAPI
api :: ListId -> GargServer API
api l = get l :<|> postAsync l :<|> csvPostAsync l
data HTML
instance Accept HTML where
contentType _ = "text" // "html" /: ("charset", "utf-8")
instance ToJSON a => MimeRender HTML a where
mimeRender _ = encode
api :: ListId -> GargServer API
api l = get l :<|> postAsync l :<|> csvPostAsync l
----------------------
type GETAPI = Summary "Get List"
:> "lists"
:> Capture "listId" ListId
:> Get '[JSON, HTML] (Headers '[Header "Content-Disposition" Text] NgramsList)
getApi :: GargServer GETAPI
getApi = get
----------------------
type JSONAPI = Summary "Update List"
:> "lists"
:> Capture "listId" ListId
:> "add"
:> "form"
:> "async"
:> AsyncJobs JobLog '[FormUrlEncoded] WithFile JobLog
jsonApi :: GargServer JSONAPI
jsonApi = postAsync
----------------------
type CSVAPI = Summary "Update List (legacy v3 CSV)"
:> "lists"
:> Capture "listId" ListId
:> "csv"
:> "add"
:> "form"
:> "async"
:> AsyncJobs JobLog '[FormUrlEncoded] WithFile JobLog
csvApi :: GargServer CSVAPI
csvApi = csvPostAsync
----------------------
------------------------------------------------------------------------
get :: RepoCmdM env err m =>
ListId -> m (Headers '[Header "Content-Disposition" Text] NgramsList)
......@@ -97,6 +136,7 @@ post :: FlowCmdM env err m
-> m Bool
post l m = do
-- TODO check with Version for optim
printDebug "New list as file" l
_ <- mapM (\(nt, Versioned _v ns) -> setListNgrams l nt ns) $ toList m
-- TODO reindex
pure True
......@@ -182,10 +222,15 @@ type PostAPI = Summary "Update List"
:> "async"
:> AsyncJobs JobLog '[FormUrlEncoded] WithFile JobLog
postAsync :: ListId -> GargServer PostAPI
postAsync :: GargServer JSONAPI
postAsync lId =
serveJobsAPI $
JobFunction (\f log' -> postAsync' lId f (liftBase . log'))
JobFunction (\f log' ->
let
log'' x = do
printDebug "postAsync ListId" x
liftBase $ log' x
in postAsync' lId f log'')
postAsync' :: FlowCmdM env err m
=> ListId
......@@ -199,7 +244,9 @@ postAsync' l (WithFile _ m _) logStatus = do
, _scst_remaining = Just 1
, _scst_events = Just []
}
_r <- post l m
printDebug "New list as file" l
_ <- post l m
-- printDebug "Done" r
pure JobLog { _scst_succeeded = Just 1
, _scst_failed = Just 0
......@@ -214,7 +261,7 @@ type CSVPostAPI = Summary "Update List (legacy v3 CSV)"
:> "async"
:> AsyncJobs JobLog '[FormUrlEncoded] WithFile JobLog
csvPostAsync :: ListId -> GargServer PostAPI
csvPostAsync :: GargServer CSVAPI
csvPostAsync lId =
serveJobsAPI $
JobFunction $ \f@(WithFile ft _ n) log' -> do
......
......@@ -160,9 +160,11 @@ type GargPrivateAPI' =
-- :<|> "scraper" :> WithCallbacks ScraperAPI
-- :<|> "new" :> New.Api
:<|> "lists" :> Summary "List export API"
:> Capture "listId" ListId
:> List.API
-- TODO refactor the 3 routes below
:<|> List.GETAPI
:<|> List.JSONAPI
:<|> List.CSVAPI
{-
:<|> "wait" :> Summary "Wait test"
:> Capture "x" Int
......@@ -237,7 +239,9 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid))
-- :<|> addAnnuaireWithForm
-- :<|> New.api uid -- TODO-SECURITY
-- :<|> New.info uid -- TODO-SECURITY
:<|> List.api
:<|> List.getApi
:<|> List.jsonApi
:<|> List.csvApi
-- :<|> waitAPI
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment