]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Node/Corpus/Annuaire.hs
[haddock] haddock builds correclty now
[gargantext.git] / src / Gargantext / API / Node / Corpus / Annuaire.hs
1 {-|
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
8 Portability : POSIX
9 -}
10
11 {-# LANGUAGE TemplateHaskell #-}
12 {-# LANGUAGE TypeOperators #-}
13
14 module Gargantext.API.Node.Corpus.Annuaire
15 where
16
17 import Control.Lens hiding (elements)
18 import Data.Aeson
19 import Data.Swagger
20 import Data.Text (Text)
21 import GHC.Generics (Generic)
22 import Servant
23 import Servant.Job.Core
24 import Servant.Job.Types
25 import Servant.Job.Utils (jsonOptions)
26 import Web.FormUrlEncoded (FromForm)
27
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
35
36
37 type Api = Summary "New Annuaire endpoint"
38 :> Post '[JSON] AnnuaireId
39
40 ------------------------------------------------------------------------
41 ------------------------------------------------------------------------
42 data AnnuaireWithForm = AnnuaireWithForm
43 { _wf_filetype :: !NewFile.FileType
44 , _wf_data :: !Text
45 , _wf_lang :: !(Maybe Lang)
46 } deriving (Eq, Show, Generic)
47
48 makeLenses ''AnnuaireWithForm
49 instance FromForm AnnuaireWithForm
50 instance FromJSON AnnuaireWithForm where
51 parseJSON = genericParseJSON $ jsonOptions "_wf_"
52 instance ToJSON AnnuaireWithForm where
53 toJSON = genericToJSON $ jsonOptions "_wf_"
54
55 instance ToSchema AnnuaireWithForm where
56 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_wf_")
57
58 ------------------------------------------------------------------------
59 type AsyncJobs event ctI input output =
60 AsyncJobsAPI' 'Unsafe 'Safe ctI '[JSON] Maybe event input output
61 ------------------------------------------------------------------------
62
63 type AddWithForm = Summary "Add with FormUrlEncoded to annuaire endpoint"
64 :> "annuaire"
65 :> Capture "annuaire_id" AnnuaireId
66 :> "add"
67 :> "form"
68 :> "async"
69 :> AsyncJobs JobLog '[FormUrlEncoded] AnnuaireWithForm JobLog
70
71 ------------------------------------------------------------------------
72 addToAnnuaireWithForm :: FlowCmdM env err m
73 => AnnuaireId
74 -> AnnuaireWithForm
75 -> (JobLog -> m ())
76 -> m JobLog
77 addToAnnuaireWithForm _cid (AnnuaireWithForm ft _d _l) logStatus = do
78
79 printDebug "ft" ft
80
81 logStatus JobLog { _scst_succeeded = Just 1
82 , _scst_failed = Just 0
83 , _scst_remaining = Just 1
84 , _scst_events = Just []
85 }
86 pure JobLog { _scst_succeeded = Just 2
87 , _scst_failed = Just 0
88 , _scst_remaining = Just 0
89 , _scst_events = Just []
90 }
91