]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
Merge branch 'dev' into 104-dev-john-snow-nlp
[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.Core.NodeStory
20 import Gargantext.Core.Mail.Types (HasMail, mailSettings)
21 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
22 import Gargantext.Prelude
23 import Gargantext.Prelude.Config (GargConfig(..))
24 import Gargantext.Prelude.Mail.Types (MailConfig)
25
26 data Env = Env
27 { _env_settings :: !Settings
28 , _env_logger :: !LoggerSet
29 , _env_pool :: !(Pool Connection)
30 , _env_nodeStory :: !NodeStoryEnv
31 , _env_manager :: !Manager
32 , _env_self_url :: !BaseUrl
33 , _env_scrapers :: !ScrapersEnv
34 , _env_config :: !GargConfig
35 , _env_mail :: !MailConfig
36 }
37 deriving (Generic)
38
39 makeLenses ''Env
40
41 instance HasConfig Env where
42 hasConfig = env_config
43
44 instance HasConnectionPool Env where
45 connPool = env_pool
46
47 instance HasNodeStoryEnv Env where
48 hasNodeStory = env_nodeStory
49
50 instance HasNodeStoryVar Env where
51 hasNodeStoryVar = hasNodeStory . nse_getter
52
53 instance HasNodeStorySaver Env where
54 hasNodeStorySaver = hasNodeStory . nse_saver
55
56 instance HasSettings Env where
57 settings = env_settings
58
59 instance HasMail Env where
60 mailSettings = env_mail
61
62
63 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
64 _env = env_scrapers . Servant.Job.Core._env
65
66 instance HasJobEnv Env JobLog JobLog where
67 job_env = env_scrapers
68
69 data MockEnv = MockEnv
70 { _menv_firewall :: !FireWall
71 }
72 deriving (Generic)
73
74 makeLenses ''MockEnv
75
76
77
78 data DevEnv = DevEnv
79 { _dev_env_settings :: !Settings
80 , _dev_env_config :: !GargConfig
81 , _dev_env_pool :: !(Pool Connection)
82 , _dev_env_nodeStory :: !NodeStoryEnv
83 , _dev_env_mail :: !MailConfig
84 }
85
86 makeLenses ''DevEnv
87
88 instance HasConfig DevEnv where
89 hasConfig = dev_env_config
90
91 instance HasConnectionPool DevEnv where
92 connPool = dev_env_pool
93
94 instance HasSettings DevEnv where
95 settings = dev_env_settings
96
97
98 instance HasNodeStoryEnv DevEnv where
99 hasNodeStory = dev_env_nodeStory
100
101 instance HasNodeStoryVar DevEnv where
102 hasNodeStoryVar = hasNodeStory . nse_getter
103
104 instance HasNodeStorySaver DevEnv where
105 hasNodeStorySaver = hasNodeStory . nse_saver
106
107 instance HasMail DevEnv where
108 mailSettings = dev_env_mail