/ src / Gargantext / API / Context.hs
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 Prelude
22  
23  import Data.Aeson (FromJSON, ToJSON)
24  import Servant
25  
26  import Gargantext.API.Admin.Auth (withAccess)
27  import Gargantext.API.Admin.Auth.Types (PathId(..), AuthenticatedUser)
28  import Gargantext.API.Prelude
29  import Gargantext.Database.Admin.Types.Node
30  import Gargantext.Database.Prelude (JSONB)
31  import Gargantext.Database.Query.Table.Context
32  
33  -------------------------------------------------------------------
34  -- TODO use Context instead of Node
35  type ContextAPI a = Get '[JSON] (Node a)
36  
37  ------------------------------------------------------------------------
38  -- TODO NodeAPI -> ContextAPI
39  contextAPI :: forall proxy a.
40         ( JSONB a
41         , FromJSON a
42         , ToJSON a
43         ) => proxy a
44           -> AuthenticatedUser
45           -> ContextId
46           -> GargServer (ContextAPI a)
47  contextAPI p uId id' = withAccess (Proxy :: Proxy (ContextAPI a)) Proxy uId (PathNode $ contextId2NodeId id') contextAPI'
48    where
49      contextAPI' :: GargServer (ContextAPI a)
50      contextAPI' = getContextWith   id' p