Commit 0877ea16 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph] graph versoin refresh endpoint

parent 6d814c37
Pipeline #793 failed with stage
...@@ -12,8 +12,8 @@ commentary with @some markup@. ...@@ -12,8 +12,8 @@ commentary with @some markup@.
-} -}
------------------------------------------------------------------------ ------------------------------------------------------------------------
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module Gargantext.Core.Types ( module Gargantext.Core.Types.Main module Gargantext.Core.Types ( module Gargantext.Core.Types.Main
......
...@@ -12,13 +12,14 @@ Portability : POSIX ...@@ -12,13 +12,14 @@ Portability : POSIX
{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
{-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
{-# LANGUAGE DataKinds #-} {-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module Gargantext.Viz.Graph.API module Gargantext.Viz.Graph.API
...@@ -28,7 +29,11 @@ import Debug.Trace (trace) ...@@ -28,7 +29,11 @@ import Debug.Trace (trace)
import Control.Concurrent -- (forkIO) import Control.Concurrent -- (forkIO)
import Control.Lens (set, (^.), _Just, (^?)) import Control.Lens (set, (^.), _Just, (^?))
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Data.Aeson
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Swagger
import GHC.Generics (Generic)
import Gargantext.API.Ngrams (NgramsRepo, r_version) import Gargantext.API.Ngrams (NgramsRepo, r_version)
import Gargantext.API.Ngrams.Tools import Gargantext.API.Ngrams.Tools
import Gargantext.API.Types import Gargantext.API.Types
...@@ -58,14 +63,22 @@ import qualified Data.Map as Map ...@@ -58,14 +63,22 @@ import qualified Data.Map as Map
type GraphAPI = Get '[JSON] Graph type GraphAPI = Get '[JSON] Graph
:<|> Post '[JSON] [GraphId] :<|> Post '[JSON] [GraphId]
:<|> Put '[JSON] Int :<|> Put '[JSON] Int
:<|> GraphAsync :<|> GraphAsyncAPI
:<|> "versions" :> GraphVersionsAPI
data GraphVersions = GraphVersions { gv_graph :: Maybe Int
, gv_repo :: Int } deriving (Show, Generic)
instance ToJSON GraphVersions
instance ToSchema GraphVersions
graphAPI :: UserId -> NodeId -> GargServer GraphAPI graphAPI :: UserId -> NodeId -> GargServer GraphAPI
graphAPI u n = getGraph u n graphAPI u n = getGraph u n
:<|> postGraph n :<|> postGraph n
:<|> putGraph n :<|> putGraph n
:<|> graphAsync u n :<|> graphAsync u n
:<|> graphVersionsAPI u n
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -196,11 +209,11 @@ putGraph = undefined ...@@ -196,11 +209,11 @@ putGraph = undefined
------------------------------------------------------------ ------------------------------------------------------------
type GraphAsync = Summary "Update graph" type GraphAsyncAPI = Summary "Update graph"
:> "async" :> "async"
:> AsyncJobsAPI ScraperStatus () ScraperStatus :> AsyncJobsAPI ScraperStatus () ScraperStatus
graphAsync :: UserId -> NodeId -> GargServer GraphAsync graphAsync :: UserId -> NodeId -> GargServer GraphAsyncAPI
graphAsync u n = graphAsync u n =
serveJobsAPI $ serveJobsAPI $
JobFunction (\_ log' -> graphAsync' u n (liftIO . log')) JobFunction (\_ log' -> graphAsync' u n (liftIO . log'))
...@@ -222,3 +235,34 @@ graphAsync' u n logStatus = do ...@@ -222,3 +235,34 @@ graphAsync' u n logStatus = do
, _scst_remaining = Just 0 , _scst_remaining = Just 0
, _scst_events = Just [] , _scst_events = Just []
} }
------------------------------------------------------------
type GraphVersionsAPI = Summary "Graph versions"
:> Get '[JSON] GraphVersions
:<|> Summary "Recompute graph version"
:> Post '[JSON] Graph
graphVersionsAPI :: UserId -> NodeId -> GargServer GraphVersionsAPI
graphVersionsAPI u n =
graphVersions u n
:<|> recomputeVersions u n
graphVersions :: UserId -> NodeId -> GargNoServer GraphVersions
graphVersions _uId nId = do
nodeGraph <- getNodeWith nId HyperdataGraph
let graph = nodeGraph ^. node_hyperdata . hyperdataGraph
let listVersion = graph ^? _Just
. graph_metadata
. _Just
. gm_list
. lfg_version
repo <- getRepo
let v = repo ^. r_version
pure $ GraphVersions { gv_graph = listVersion
, gv_repo = v }
recomputeVersions :: UserId -> NodeId -> GargNoServer Graph
recomputeVersions uId nId = recomputeGraph uId nId
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment