import Control.Lens hiding (elements)
import Data.Aeson
-import Data.List (zip)
import Data.Map (Map, toList, fromList)
import Data.Swagger (ToSchema, declareNamedSchema, genericDeclareNamedSchema)
import Data.Text (Text, concat, pack)
import GHC.Generics (Generic)
-import Gargantext.API.Node.Corpus.New
-import Gargantext.API.Node.Corpus.New.File (FileType(..))
-import Gargantext.API.Ngrams
+import Network.HTTP.Media ((//), (/:))
+import Servant
+import Servant.Job.Async
+import Servant.Job.Utils (jsonOptions)
+import Web.FormUrlEncoded (FromForm)
+
import Gargantext.API.Admin.Orchestrator.Types
+import Gargantext.API.Ngrams (getNgramsTableMap, setListNgrams)
+import Gargantext.API.Ngrams.Types (NgramsTableMap, RepoCmdM, Versioned(..))
+import Gargantext.API.Node.Corpus.New.File (FileType(..))
import Gargantext.API.Prelude (GargServer)
import Gargantext.Core.Utils.Prefix (unPrefixSwagger)
-import Gargantext.Database.Action.Flow (FlowCmdM)
+import Gargantext.Database.Action.Flow.Types (FlowCmdM)
import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Schema.Ngrams (NgramsType(..), ngramsTypes)
import Gargantext.Prelude
-import Network.HTTP.Media ((//), (/:))
-import Servant
-import Servant.Job.Async
-import Servant.Job.Utils (jsonOptions)
-import Web.FormUrlEncoded (FromForm)
------------------------------------------------------------------------
type NgramsList = (Map NgramsType (Versioned NgramsTableMap))
mimeRender _ = encode
------------------------------------------------------------------------
-
-get :: RepoCmdM env err m
- => ListId -> m (Headers '[Header "Content-Disposition" Text] NgramsList)
+get :: RepoCmdM env err m =>
+ ListId -> m (Headers '[Header "Content-Disposition" Text] NgramsList)
get lId = do
lst <- get' lId
let (NodeId id) = lId
<$> mapM (getNgramsTableMap lId) ngramsTypes
------------------------------------------------------------------------
-
-- TODO : purge list
+-- TODO talk
post :: FlowCmdM env err m
=> ListId
-> NgramsList
------------------------------------------------------------------------
------------------------------------------------------------------------
-
type PostAPI = Summary "Update List"
:> "add"
:> "form"
:> "async"
- :> AsyncJobs ScraperStatus '[FormUrlEncoded] WithFile ScraperStatus
+ :> AsyncJobs JobLog '[FormUrlEncoded] WithFile JobLog
postAsync :: ListId -> GargServer PostAPI
postAsync lId =
postAsync' :: FlowCmdM env err m
=> ListId
-> WithFile
- -> (ScraperStatus -> m ())
- -> m ScraperStatus
+ -> (JobLog -> m ())
+ -> m JobLog
postAsync' l (WithFile _ m _) logStatus = do
- logStatus ScraperStatus { _scst_succeeded = Just 0
- , _scst_failed = Just 0
- , _scst_remaining = Just 1
- , _scst_events = Just []
- }
+ logStatus JobLog { _scst_succeeded = Just 0
+ , _scst_failed = Just 0
+ , _scst_remaining = Just 1
+ , _scst_events = Just []
+ }
_r <- post l m
- pure ScraperStatus { _scst_succeeded = Just 1
- , _scst_failed = Just 0
- , _scst_remaining = Just 0
- , _scst_events = Just []
- }
+ pure JobLog { _scst_succeeded = Just 1
+ , _scst_failed = Just 0
+ , _scst_remaining = Just 0
+ , _scst_events = Just []
+ }
data WithFile = WithFile
{ _wf_filetype :: !FileType