]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[FIX] list heritage (into NodeStory)
[gargantext.git] / src / Gargantext / API / Admin / EnvTypes.hs
1 -- |
2
3 {-# LANGUAGE TemplateHaskell #-}
4
5 module Gargantext.API.Admin.EnvTypes where
6
7 import Control.Lens
8 import Data.Pool (Pool)
9 import Database.PostgreSQL.Simple (Connection)
10 import GHC.Generics (Generic)
11 import Network.HTTP.Client (Manager)
12 import Servant.Client (BaseUrl)
13 import Servant.Job.Async (HasJobEnv(..), Job)
14 import System.Log.FastLogger
15 import qualified Servant.Job.Core
16
17 import Gargantext.API.Ngrams.Types (HasRepoVar(..), HasRepoSaver(..), HasRepo(..), RepoEnv(..))
18 import Gargantext.API.Admin.Types
19 import Gargantext.API.Admin.Orchestrator.Types
20 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
21 import Gargantext.Prelude
22 import Gargantext.Prelude.Config (GargConfig(..))
23 import Gargantext.Core.NodeStory
24
25 data Env = Env
26 { _env_settings :: !Settings
27 , _env_logger :: !LoggerSet
28 , _env_pool :: !(Pool Connection)
29 , _env_repo :: !RepoEnv
30 , _env_nodeStory :: !NodeStoryEnv
31 , _env_manager :: !Manager
32 , _env_self_url :: !BaseUrl
33 , _env_scrapers :: !ScrapersEnv
34 , _env_config :: !GargConfig
35 }
36 deriving (Generic)
37
38 makeLenses ''Env
39
40 instance HasConfig Env where
41 hasConfig = env_config
42
43 instance HasConnectionPool Env where
44 connPool = env_pool
45
46 instance HasNodeStoryEnv Env where
47 hasNodeStory = env_nodeStory
48
49 instance HasNodeStoryVar Env where
50 hasNodeStoryVar = hasNodeStory . nse_getter
51
52 instance HasNodeStorySaver Env where
53 hasNodeStorySaver = hasNodeStory . nse_saver
54
55 instance HasSettings Env where
56 settings = env_settings
57
58 -- Specific to Repo
59 instance HasRepoVar Env where
60 repoVar = repoEnv . repoVar
61 instance HasRepoSaver Env where
62 repoSaver = repoEnv . repoSaver
63 instance HasRepo Env where
64 repoEnv = env_repo
65
66
67
68
69 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
70 _env = env_scrapers . Servant.Job.Core._env
71
72 instance HasJobEnv Env JobLog JobLog where
73 job_env = env_scrapers
74
75 data MockEnv = MockEnv
76 { _menv_firewall :: !FireWall
77 }
78 deriving (Generic)
79
80 makeLenses ''MockEnv
81
82
83
84 data DevEnv = DevEnv
85 { _dev_env_settings :: !Settings
86 , _dev_env_repo :: !RepoEnv
87 , _dev_env_config :: !GargConfig
88 , _dev_env_pool :: !(Pool Connection)
89 , _dev_env_nodeStory :: !NodeStoryEnv
90 }
91
92 makeLenses ''DevEnv
93
94 instance HasConfig DevEnv where
95 hasConfig = dev_env_config
96
97 instance HasConnectionPool DevEnv where
98 connPool = dev_env_pool
99
100 instance HasSettings DevEnv where
101 settings = dev_env_settings
102
103
104 instance HasNodeStoryEnv DevEnv where
105 hasNodeStory = dev_env_nodeStory
106
107 instance HasNodeStoryVar DevEnv where
108 hasNodeStoryVar = hasNodeStory . nse_getter
109
110 instance HasNodeStorySaver DevEnv where
111 hasNodeStorySaver = hasNodeStory . nse_saver
112
113
114 instance HasRepoVar DevEnv where
115 repoVar = repoEnv . repoVar
116 instance HasRepoSaver DevEnv where
117 repoSaver = repoEnv . repoSaver
118 instance HasRepo DevEnv where
119 repoEnv = dev_env_repo
120
121