]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[DOC] IsTex API TODO for alter
[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 HasNodeStoryImmediateSaver Env where
57 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
58
59 instance HasSettings Env where
60 settings = env_settings
61
62 instance HasMail Env where
63 mailSettings = env_mail
64
65
66 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
67 _env = env_scrapers . Servant.Job.Core._env
68
69 instance HasJobEnv Env JobLog JobLog where
70 job_env = env_scrapers
71
72 data MockEnv = MockEnv
73 { _menv_firewall :: !FireWall
74 }
75 deriving (Generic)
76
77 makeLenses ''MockEnv
78
79
80
81 data DevEnv = DevEnv
82 { _dev_env_settings :: !Settings
83 , _dev_env_config :: !GargConfig
84 , _dev_env_pool :: !(Pool Connection)
85 , _dev_env_nodeStory :: !NodeStoryEnv
86 , _dev_env_mail :: !MailConfig
87 }
88
89 makeLenses ''DevEnv
90
91 instance HasConfig DevEnv where
92 hasConfig = dev_env_config
93
94 instance HasConnectionPool DevEnv where
95 connPool = dev_env_pool
96
97 instance HasSettings DevEnv where
98 settings = dev_env_settings
99
100
101 instance HasNodeStoryEnv DevEnv where
102 hasNodeStory = dev_env_nodeStory
103
104 instance HasNodeStoryVar DevEnv where
105 hasNodeStoryVar = hasNodeStory . nse_getter
106
107 instance HasNodeStorySaver DevEnv where
108 hasNodeStorySaver = hasNodeStory . nse_saver
109
110 instance HasNodeStoryImmediateSaver DevEnv where
111 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
112
113 instance HasMail DevEnv where
114 mailSettings = dev_env_mail