]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Context.hs
[nodeStory] some more config repo path refactoring
[gargantext.git] / src / Gargantext / API / Context.hs
1 {-|
2 Module : Gargantext.API.Context
3 Description : Server API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE ScopedTypeVariables #-}
15 {-# LANGUAGE TemplateHaskell #-}
16 {-# LANGUAGE TypeOperators #-}
17
18 module Gargantext.API.Context
19 where
20
21 import Data.Aeson (FromJSON, ToJSON)
22 import Servant
23
24 import Gargantext.API.Admin.Auth (withAccess)
25 import Gargantext.API.Admin.Auth.Types (PathId(..))
26 import Gargantext.API.Prelude
27 import Gargantext.Database.Admin.Types.Node
28 import Gargantext.Database.Prelude -- (Cmd, CmdM)
29 import Gargantext.Database.Query.Table.Context
30
31 -------------------------------------------------------------------
32 -- TODO use Context instead of Node
33 type ContextAPI a = Get '[JSON] (Node a)
34
35 ------------------------------------------------------------------------
36 -- TODO NodeAPI -> ContextAPI
37 contextAPI :: forall proxy a.
38 ( JSONB a
39 , FromJSON a
40 , ToJSON a
41 ) => proxy a
42 -> UserId
43 -> ContextId
44 -> GargServer (ContextAPI a)
45 contextAPI p uId id' = withAccess (Proxy :: Proxy (ContextAPI a)) Proxy uId (PathNode id') contextAPI'
46 where
47 contextAPI' :: GargServer (ContextAPI a)
48 contextAPI' = getContextWith id' p