Commit a11c6b4d authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[list] added v3 CSV upload endpoint

NOTE: This is a copy of uploadAPI, i.e. it parses JSON currently.
parent e841d483
Pipeline #1654 passed with stage
in 22 minutes and 21 seconds
......@@ -58,9 +58,10 @@ import qualified Data.Text as Text
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
api l = get l :<|> postAsync l :<|> csvPostAsync l
data HTML
instance Accept HTML where
......@@ -164,7 +165,6 @@ toIndexedNgrams m t = Indexed <$> i <*> n
i = HashMap.lookup t m
n = Just (text2ngrams t)
------------------------------------------------------------------------
------------------------------------------------------------------------
type PostAPI = Summary "Update List"
:> "add"
......@@ -196,6 +196,38 @@ postAsync' l (WithFile _ m _) logStatus = do
, _scst_remaining = Just 0
, _scst_events = Just []
}
------------------------------------------------------------------------
type CSVPostAPI = Summary "Update List (legacy v3 CSV)"
:> "csv"
:> "form"
:> "async"
:> AsyncJobs JobLog '[FormUrlEncoded] WithFile JobLog
csvPostAsync :: ListId -> GargServer PostAPI
csvPostAsync lId =
serveJobsAPI $
JobFunction (\f log' -> csvPostAsync' lId f (liftBase . log'))
csvPostAsync' :: FlowCmdM env err m
=> ListId
-> WithFile
-> (JobLog -> m ())
-> m JobLog
csvPostAsync' l (WithFile _ m _) logStatus = do
logStatus JobLog { _scst_succeeded = Just 0
, _scst_failed = Just 0
, _scst_remaining = Just 1
, _scst_events = Just []
}
_r <- post l m
pure JobLog { _scst_succeeded = Just 1
, _scst_failed = Just 0
, _scst_remaining = Just 0
, _scst_events = Just []
}
------------------------------------------------------------------------
data WithFile = WithFile
{ _wf_filetype :: !FileType
......
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