]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Node/Corpus/Types.hs
Simplify ExternalAPIs type
[gargantext.git] / src / Gargantext / API / Node / Corpus / Types.hs
1 {-# LANGUAGE TemplateHaskell #-}
2
3 module Gargantext.API.Node.Corpus.Types where
4
5 import Control.Lens hiding (elements, Empty)
6 import Data.Aeson
7 import Data.Aeson.TH (deriveJSON)
8 import Data.Monoid (mempty)
9 import Data.Swagger
10 import GHC.Generics (Generic)
11
12 import Gargantext.Prelude
13
14 import qualified Gargantext.API.Admin.Orchestrator.Types as T
15 import Gargantext.Core.Utils.Prefix (unPrefix)
16 import Gargantext.Database.Action.Flow (DataOrigin(..))
17
18 data Database = Empty
19 | PubMed
20 | Arxiv
21 | HAL
22 | IsTex
23 | Isidore
24 deriving (Eq, Show, Generic, Enum, Bounded)
25
26 deriveJSON (unPrefix "") ''Database
27 instance ToSchema Database where
28 declareNamedSchema = genericDeclareNamedSchemaUnrestricted defaultSchemaOptions
29
30 database2origin :: Database -> DataOrigin
31 database2origin Empty = InternalOrigin T.IsTex
32 database2origin PubMed = ExternalOrigin T.PubMed
33 database2origin Arxiv = ExternalOrigin T.Arxiv
34 database2origin HAL = ExternalOrigin T.HAL
35 database2origin IsTex = ExternalOrigin T.IsTex
36 database2origin Isidore = ExternalOrigin T.Isidore
37
38 ------------------------------------------------------------------------
39 data Datafield = Gargantext
40 | External Database
41 | Web
42 | Files
43 deriving (Eq, Show, Generic)
44
45 instance FromJSON Datafield
46 instance ToJSON Datafield
47 -- instance FromJSON Datafield where
48 -- parseJSON = withText "Datafield" $ \text ->
49 -- case text of
50 -- "Gargantext" -> pure Gargantext
51 -- "Web" -> pure Web
52 -- "Files" -> pure Files
53 -- v ->
54 -- let (preExternal, _, postExternal) = v =~ ("External " :: Text) :: (Text, Text, Text)
55 -- in
56 -- if preExternal == "" then do
57 -- db <- parseJSON $ String postExternal
58 -- pure $ External db
59 -- else fail $ "Cannot match patterh 'External <db>' for string " ++ (T.unpack v)
60 -- instance ToJSON Datafield where
61 -- toJSON (External db) = toJSON $ "External " ++ (show db)
62 -- toJSON s = toJSON $ show s
63 instance ToSchema Datafield where
64 declareNamedSchema _ = do
65 return $ NamedSchema (Just "Datafield") $ mempty
66 & type_ ?~ SwaggerObject