2 Module : Gargantext.API.Node.Corpus.Annuaire
3 Description : New annuaire API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 {-# LANGUAGE TemplateHaskell #-}
12 {-# LANGUAGE TypeOperators #-}
14 module Gargantext.API.Node.Corpus.Annuaire
17 import Control.Lens hiding (elements)
20 import Data.Text (Text)
21 import GHC.Generics (Generic)
23 import Servant.Job.Core
24 import Servant.Job.Types
25 import Servant.Job.Utils (jsonOptions)
26 import Web.FormUrlEncoded (FromForm)
28 import qualified Gargantext.API.Node.Corpus.New.File as NewFile
29 import Gargantext.API.Admin.Orchestrator.Types hiding (AsyncJobs)
30 import Gargantext.Core (Lang(..))
31 import Gargantext.Core.Utils.Prefix (unPrefixSwagger)
32 import Gargantext.Database.Action.Flow.Types (FlowCmdM) -- flowAnnuaire
33 import Gargantext.Database.Admin.Types.Node (AnnuaireId)
34 import Gargantext.Prelude
37 type Api = Summary "New Annuaire endpoint"
38 :> Post '[JSON] AnnuaireId
40 ------------------------------------------------------------------------
41 ------------------------------------------------------------------------
42 data AnnuaireWithForm = AnnuaireWithForm
43 { _wf_filetype :: !NewFile.FileType
45 , _wf_lang :: !(Maybe Lang)
46 } deriving (Eq, Show, Generic)
48 makeLenses ''AnnuaireWithForm
49 instance FromForm AnnuaireWithForm
50 instance FromJSON AnnuaireWithForm where
51 parseJSON = genericParseJSON $ jsonOptions "_wf_"
52 instance ToSchema AnnuaireWithForm where
53 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_wf_")
55 ------------------------------------------------------------------------
56 type AsyncJobs event ctI input output =
57 AsyncJobsAPI' 'Unsafe 'Safe ctI '[JSON] Maybe event input output
58 ------------------------------------------------------------------------
60 type AddWithForm = Summary "Add with FormUrlEncoded to annuaire endpoint"
62 :> Capture "annuaire_id" AnnuaireId
66 :> AsyncJobs JobLog '[FormUrlEncoded] AnnuaireWithForm JobLog
68 ------------------------------------------------------------------------
69 addToAnnuaireWithForm :: FlowCmdM env err m
74 addToAnnuaireWithForm _cid (AnnuaireWithForm ft _d _l) logStatus = do
78 logStatus JobLog { _scst_succeeded = Just 1
79 , _scst_failed = Just 0
80 , _scst_remaining = Just 1
81 , _scst_events = Just []
83 pure JobLog { _scst_succeeded = Just 2
84 , _scst_failed = Just 0
85 , _scst_remaining = Just 0
86 , _scst_events = Just []