]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[Types] NodeStoryEnv ready for integration in API
[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.Admin.Types
18 import Gargantext.API.Admin.Orchestrator.Types
19 import Gargantext.API.Ngrams.Types (HasRepoVar(..), HasRepoSaver(..), HasRepo(..), RepoEnv(..))
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 HasRepoVar Env where
47 repoVar = repoEnv . repoVar
48
49 instance HasRepoSaver Env where
50 repoSaver = repoEnv . repoSaver
51
52 instance HasRepo Env where
53 repoEnv = env_repo
54
55 instance HasSettings Env where
56 settings = env_settings
57
58 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
59 _env = env_scrapers . Servant.Job.Core._env
60
61 instance HasJobEnv Env JobLog JobLog where
62 job_env = env_scrapers
63
64 data MockEnv = MockEnv
65 { _menv_firewall :: !FireWall
66 }
67 deriving (Generic)
68
69 makeLenses ''MockEnv
70
71
72 data DevEnv = DevEnv
73 { _dev_env_pool :: !(Pool Connection)
74 , _dev_env_repo :: !RepoEnv
75 , _dev_env_settings :: !Settings
76 , _dev_env_config :: !GargConfig
77 }
78
79 makeLenses ''DevEnv
80
81 instance HasConfig DevEnv where
82 hasConfig = dev_env_config
83
84 instance HasConnectionPool DevEnv where
85 connPool = dev_env_pool
86
87 instance HasRepoVar DevEnv where
88 repoVar = repoEnv . repoVar
89
90 instance HasRepoSaver DevEnv where
91 repoSaver = repoEnv . repoSaver
92
93 instance HasRepo DevEnv where
94 repoEnv = dev_env_repo
95
96 instance HasSettings DevEnv where
97 settings = dev_env_settings