Commit 4caaf612 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[docs table] hashed response in docs table

parent c9674b6e
Pipeline #918 failed with stage
......@@ -38,6 +38,7 @@ library:
exposed-modules:
- Gargantext
- Gargantext.API
- Gargantext.API.HashedResponse
- Gargantext.API.Node
- Gargantext.API.Admin.Settings
- Gargantext.API.Prelude
......
module Gargantext.API.HashedResponse where
import Data.Aeson
import Data.Swagger
import qualified Data.Digest.Pure.MD5 as DPMD5
import GHC.Generics (Generic)
import Protolude
data HashedResponse a = HashedResponse { md5 :: Text, value :: a }
deriving (Generic)
instance ToSchema a => ToSchema (HashedResponse a)
instance ToJSON a => ToJSON (HashedResponse a) where
toJSON = genericToJSON defaultOptions
constructHashedResponse :: ToJSON a => a -> HashedResponse a
constructHashedResponse v = HashedResponse { md5 = md5', value = v }
where
md5' = show $ DPMD5.md5 $ encode v
\ No newline at end of file
......@@ -19,15 +19,12 @@ module Gargantext.API.Metrics
where
import Control.Lens
import Data.Aeson
import qualified Data.Digest.Pure.MD5 as DPMD5
import Data.Swagger
import Data.Time (UTCTime)
import GHC.Generics (Generic)
import Protolude
import Servant
import qualified Data.Map as Map
import Gargantext.API.HashedResponse
import Gargantext.API.Ngrams
import Gargantext.API.Ngrams.NTree
import Gargantext.API.Prelude (GargServer)
......@@ -46,18 +43,6 @@ import Gargantext.Text.Metrics (Scored(..))
import Gargantext.Viz.Chart
import Gargantext.Viz.Types
data HashedResponse a = HashedResponse { md5 :: Text, value :: a }
deriving (Generic)
instance ToSchema a => ToSchema (HashedResponse a)
instance ToJSON a => ToJSON (HashedResponse a) where
toJSON = genericToJSON defaultOptions
constructHashedResponse :: ToJSON a => a -> HashedResponse a
constructHashedResponse chart = HashedResponse { md5 = md5', value = chart }
where
md5' = show $ DPMD5.md5 $ encode chart
-------------------------------------------------------------
-- | Scatter metrics API
type ScatterAPI = Summary "SepGen IncExc metrics"
......
......@@ -148,7 +148,7 @@ data TabType = Docs | Trash | MoreFav | MoreTrash
deriving (Generic, Enum, Bounded, Show)
instance FromHttpApiData TabType
where
where
parseUrlPiece "Docs" = pure Docs
parseUrlPiece "Trash" = pure Trash
parseUrlPiece "MoreFav" = pure MoreFav
......
......@@ -40,6 +40,7 @@ import Servant
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import Gargantext.API.HashedResponse
import Gargantext.API.Ngrams (TabType(..))
import Gargantext.API.Prelude (GargServer)
import Gargantext.Core.Types (Offset, Limit, TableResult(..))
......@@ -55,10 +56,14 @@ import Gargantext.Prelude
type TableApi = Summary "Table API"
:> QueryParam "tabType" TabType
:> Get '[JSON] FacetTableResult
:> Get '[JSON] (HashedResponse FacetTableResult)
:<|> Summary "Table API (POST)"
:> ReqBody '[JSON] TableQuery
:> Post '[JSON] FacetTableResult
:<|> "md5" :>
Summary "Table md5"
:> QueryParam "tabType" TabType
:> Get '[JSON] Text
data TableQuery = TableQuery
{ tq_offset :: Int
......@@ -82,10 +87,13 @@ instance Arbitrary TableQuery where
tableApi :: NodeId -> GargServer TableApi
tableApi id' = getTableApi id'
:<|> postTableApi id'
:<|> getTableMd5Api id'
getTableApi :: NodeId -> Maybe TabType -> Cmd err FacetTableResult
getTableApi cId tabType = getTable cId tabType Nothing Nothing Nothing
getTableApi :: NodeId -> Maybe TabType -> Cmd err (HashedResponse FacetTableResult)
getTableApi cId tabType = do
t <- getTable cId tabType Nothing Nothing Nothing
pure $ constructHashedResponse t
postTableApi :: NodeId -> TableQuery -> Cmd err FacetTableResult
......@@ -95,6 +103,11 @@ postTableApi cId (TableQuery o l order ft q) = case ft of
Trash -> searchInCorpus' cId True [q] (Just o) (Just l) (Just order)
x -> panic $ "not implemented in tableApi " <> (cs $ show x)
getTableMd5Api :: NodeId -> Maybe TabType -> Cmd err Text
getTableMd5Api cId tabType = do
HashedResponse { md5 = md5' } <- getTableApi cId tabType
pure md5'
searchInCorpus' :: CorpusId
-> Bool
-> [Text]
......
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