Commit 7ac399b1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[metrics] trying to get 304 status code to work

parent 7b42e0f8
Pipeline #961 canceled with stage
...@@ -19,8 +19,11 @@ module Gargantext.API.Metrics ...@@ -19,8 +19,11 @@ module Gargantext.API.Metrics
where where
import Control.Lens import Control.Lens
import qualified Data.Map as Map
import Data.Time (UTCTime) import Data.Time (UTCTime)
import Data.Text (Text) import Data.Text (Text)
import Servant
import Gargantext.API.HashedResponse import Gargantext.API.HashedResponse
import Gargantext.API.Ngrams import Gargantext.API.Ngrams
import Gargantext.API.Ngrams.NTree import Gargantext.API.Ngrams.NTree
...@@ -39,8 +42,6 @@ import Gargantext.Prelude ...@@ -39,8 +42,6 @@ import Gargantext.Prelude
import Gargantext.Text.Metrics (Scored(..)) import Gargantext.Text.Metrics (Scored(..))
import Gargantext.Viz.Chart import Gargantext.Viz.Chart
import Gargantext.Viz.Types import Gargantext.Viz.Types
import Servant
import qualified Data.Map as Map
import qualified Gargantext.Database.Action.Metrics as Metrics import qualified Gargantext.Database.Action.Metrics as Metrics
------------------------------------------------------------- -------------------------------------------------------------
...@@ -49,7 +50,8 @@ type ScatterAPI = Summary "SepGen IncExc metrics" ...@@ -49,7 +50,8 @@ type ScatterAPI = Summary "SepGen IncExc metrics"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> QueryParam "limit" Int :> QueryParam "limit" Int
:> Get '[JSON] (HashedResponse Metrics) :> Header "X-Hash" Text
:> Get '[JSON] (Headers '[Header "X-Hash" Text] (HashedResponse Metrics))
:<|> Summary "Scatter update" :<|> Summary "Scatter update"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
...@@ -71,8 +73,9 @@ getScatter :: FlowCmdM env err m => ...@@ -71,8 +73,9 @@ getScatter :: FlowCmdM env err m =>
-> Maybe ListId -> Maybe ListId
-> TabType -> TabType
-> Maybe Limit -> Maybe Limit
-> m (HashedResponse Metrics) -> Maybe Text
getScatter cId maybeListId tabType _maybeLimit = do -> m (Headers '[Header "X-Hash" Text] (HashedResponse Metrics))
getScatter cId maybeListId tabType _maybeLimit mhHash = do
listId <- case maybeListId of listId <- case maybeListId of
Just lid -> pure lid Just lid -> pure lid
Nothing -> defaultList cId Nothing -> defaultList cId
...@@ -84,7 +87,16 @@ getScatter cId maybeListId tabType _maybeLimit = do ...@@ -84,7 +87,16 @@ getScatter cId maybeListId tabType _maybeLimit = do
Nothing -> do Nothing -> do
updateScatter' cId maybeListId tabType Nothing updateScatter' cId maybeListId tabType Nothing
pure $ constructHashedResponse chart let r = constructHashedResponse chart
-- TODO send 304 if hashes equal, 200 with response otherwise
if mhHash == (Just $ hash r) then
throwError $ ServantErr { errHTTPCode = 304
, errReasonPhrase = "Hashes match"
, errBody = ""
, errHeaders = []}
else
pure $ addHeader (hash r) r
updateScatter :: FlowCmdM env err m => updateScatter :: FlowCmdM env err m =>
CorpusId CorpusId
...@@ -126,7 +138,8 @@ getScatterHash :: FlowCmdM env err m => ...@@ -126,7 +138,8 @@ getScatterHash :: FlowCmdM env err m =>
-> TabType -> TabType
-> m Text -> m Text
getScatterHash cId maybeListId tabType = do getScatterHash cId maybeListId tabType = do
hash <$> getScatter cId maybeListId tabType Nothing r <- getScatter cId maybeListId tabType Nothing Nothing
pure $ hash $ getResponse r
------------------------------------------------------------- -------------------------------------------------------------
......
...@@ -56,8 +56,8 @@ instance ToJSON a => MimeRender HTML a where ...@@ -56,8 +56,8 @@ instance ToJSON a => MimeRender HTML a where
------------------------------------------------------------------------ ------------------------------------------------------------------------
get :: RepoCmdM env err m get :: RepoCmdM env err m =>
=> ListId -> m (Headers '[Header "Content-Disposition" Text] NgramsList) ListId -> m (Headers '[Header "Content-Disposition" Text] NgramsList)
get lId = do get lId = do
lst <- get' lId lst <- get' lId
let (NodeId id) = lId let (NodeId id) = lId
......
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