]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[REFACT] SocialList main
[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
24
25 data Env = Env
26 { _env_settings :: !Settings
27 , _env_logger :: !LoggerSet
28 , _env_pool :: !(Pool Connection)
29 , _env_repo :: !RepoEnv
30 , _env_manager :: !Manager
31 , _env_self_url :: !BaseUrl
32 , _env_scrapers :: !ScrapersEnv
33 , _env_config :: !GargConfig
34 }
35 deriving (Generic)
36
37 makeLenses ''Env
38
39 instance HasConfig Env where
40 config = env_config
41
42 instance HasConnectionPool Env where
43 connPool = env_pool
44
45 instance HasRepoVar Env where
46 repoVar = repoEnv . repoVar
47
48 instance HasRepoSaver Env where
49 repoSaver = repoEnv . repoSaver
50
51 instance HasRepo Env where
52 repoEnv = env_repo
53
54 instance HasSettings Env where
55 settings = env_settings
56
57 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
58 _env = env_scrapers . Servant.Job.Core._env
59
60 instance HasJobEnv Env JobLog JobLog where
61 job_env = env_scrapers
62
63 data MockEnv = MockEnv
64 { _menv_firewall :: !FireWall
65 }
66 deriving (Generic)
67
68 makeLenses ''MockEnv
69
70
71 data DevEnv = DevEnv
72 { _dev_env_pool :: !(Pool Connection)
73 , _dev_env_repo :: !RepoEnv
74 , _dev_env_settings :: !Settings
75 , _dev_env_config :: !GargConfig
76 }
77
78 makeLenses ''DevEnv
79
80 instance HasConfig DevEnv where
81 config = dev_env_config
82
83 instance HasConnectionPool DevEnv where
84 connPool = dev_env_pool
85
86 instance HasRepoVar DevEnv where
87 repoVar = repoEnv . repoVar
88
89 instance HasRepoSaver DevEnv where
90 repoSaver = repoEnv . repoSaver
91
92 instance HasRepo DevEnv where
93 repoEnv = dev_env_repo
94
95 instance HasSettings DevEnv where
96 settings = dev_env_settings