Commit fa4332db authored by Alexandre Delanoë's avatar Alexandre Delanoë
parents 110c6265 1a51c9b2
...@@ -71,7 +71,7 @@ import Text.Blaze.Html (Html) ...@@ -71,7 +71,7 @@ import Text.Blaze.Html (Html)
import Gargantext.API.Auth (AuthRequest, AuthResponse, auth) import Gargantext.API.Auth (AuthRequest, AuthResponse, auth)
import Gargantext.API.Count ( CountAPI, count, Query) import Gargantext.API.Count ( CountAPI, count, Query)
import Gargantext.API.FrontEnd (FrontEndAPI, frontEndServer) import Gargantext.API.FrontEnd (FrontEndAPI, frontEndServer)
import Gargantext.API.Ngrams (HasRepo(..), HasRepoSaver(..), saveRepo, ApiNgramsTableDoc, apiNgramsTableDoc) import Gargantext.API.Ngrams (HasRepo(..), HasRepoSaver(..), saveRepo, TableNgramsApi, apiNgramsTableDoc)
import Gargantext.API.Node import Gargantext.API.Node
import Gargantext.API.Search ( SearchAPI, search, SearchQuery) import Gargantext.API.Search ( SearchAPI, search, SearchQuery)
import Gargantext.API.Types import Gargantext.API.Types
...@@ -251,7 +251,7 @@ type GargAPI' = ...@@ -251,7 +251,7 @@ type GargAPI' =
-- Document endpoint -- Document endpoint
:<|> "document":> Summary "Document endpoint" :<|> "document":> Summary "Document endpoint"
:> Capture "id" DocId :> "ngrams" :> ApiNgramsTableDoc :> Capture "id" DocId :> "ngrams" :> TableNgramsApi
-- Corpus endpoint -- Corpus endpoint
:<|> "nodes" :> Summary "Nodes endpoint" :<|> "nodes" :> Summary "Nodes endpoint"
......
...@@ -200,9 +200,12 @@ mkNgramsElement ngrams list rp children = ...@@ -200,9 +200,12 @@ mkNgramsElement ngrams list rp children =
-- TODO review -- TODO review
size = 1 + count " " ngrams size = 1 + count " " ngrams
newNgramsElement :: NgramsTerm -> NgramsElement
newNgramsElement ngrams = mkNgramsElement ngrams GraphTerm Nothing mempty
instance ToSchema NgramsElement instance ToSchema NgramsElement
instance Arbitrary NgramsElement where instance Arbitrary NgramsElement where
arbitrary = elements [mkNgramsElement "sport" GraphTerm Nothing mempty] arbitrary = elements [newNgramsElement "sport"]
ngramsElementToRepo :: NgramsElement -> NgramsRepoElement ngramsElementToRepo :: NgramsElement -> NgramsRepoElement
ngramsElementToRepo ngramsElementToRepo
...@@ -776,7 +779,7 @@ addListNgrams listId ngramsType nes = do ...@@ -776,7 +779,7 @@ addListNgrams listId ngramsType nes = do
-} -}
-- If the given list of ngrams elements contains ngrams already in -- If the given list of ngrams elements contains ngrams already in
-- the repo, they will overwrite the old ones. -- the repo, they will be ignored.
putListNgrams :: RepoCmdM env err m putListNgrams :: RepoCmdM env err m
=> NodeId -> NgramsType => NodeId -> NgramsType
-> [NgramsElement] -> m () -> [NgramsElement] -> m ()
...@@ -785,13 +788,14 @@ putListNgrams listId ngramsType nes = do ...@@ -785,13 +788,14 @@ putListNgrams listId ngramsType nes = do
-- printDebug "putListNgrams" (length nes) -- printDebug "putListNgrams" (length nes)
var <- view repoVar var <- view repoVar
liftIO $ modifyMVar_ var $ liftIO $ modifyMVar_ var $
pure . (r_state . at ngramsType %~ (Just . (at listId %~ (Just . (m <>) . something)) . something)) pure . (r_state . at ngramsType %~ (Just . (at listId %~ (Just . (<> m) . something)) . something))
saveRepo saveRepo
where where
m = Map.fromList $ (\n -> (n ^. ne_ngrams, ngramsElementToRepo n)) <$> nes m = Map.fromList $ (\n -> (n ^. ne_ngrams, ngramsElementToRepo n)) <$> nes
tableNgramsPost :: RepoCmdM env err m => TabType -> NodeId -> [NgramsElement] -> m () tableNgramsPost :: RepoCmdM env err m => TabType -> NodeId -> [NgramsTerm] -> m ()
tableNgramsPost tabType listId = putListNgrams listId (ngramsTypeFromTabType tabType) tableNgramsPost tabType listId =
putListNgrams listId (ngramsTypeFromTabType tabType) . fmap newNgramsElement
-- Apply the given patch to the DB and returns the patch to be applied on the -- Apply the given patch to the DB and returns the patch to be applied on the
-- client. -- client.
...@@ -1004,9 +1008,13 @@ type TableNgramsApiPut = Summary " Table Ngrams API Change" ...@@ -1004,9 +1008,13 @@ type TableNgramsApiPut = Summary " Table Ngrams API Change"
type TableNgramsApiPost = Summary " Table Ngrams API Adds new ngrams" type TableNgramsApiPost = Summary " Table Ngrams API Adds new ngrams"
:> QueryParamR "ngramsType" TabType :> QueryParamR "ngramsType" TabType
:> QueryParamR "list" ListId :> QueryParamR "list" ListId
:> ReqBody '[JSON] [NgramsElement] :> ReqBody '[JSON] [NgramsTerm]
:> Post '[JSON] () :> Post '[JSON] ()
type TableNgramsApi = TableNgramsApiGet
:<|> TableNgramsApiPut
:<|> TableNgramsApiPost
getTableNgramsCorpus :: (RepoCmdM env err m, HasNodeError err, HasConnection env) getTableNgramsCorpus :: (RepoCmdM env err m, HasNodeError err, HasConnection env)
=> NodeId -> TabType => NodeId -> TabType
-> ListId -> Limit -> Maybe Offset -> ListId -> Limit -> Maybe Offset
...@@ -1040,20 +1048,23 @@ getTableNgramsDoc dId tabType listId limit_ offset listType minSize maxSize orde ...@@ -1040,20 +1048,23 @@ getTableNgramsDoc dId tabType listId limit_ offset listType minSize maxSize orde
apiNgramsTableCorpus :: ( RepoCmdM env err m
, HasNodeError err
, HasInvalidError err
, HasConnection env
)
=> NodeId -> ServerT TableNgramsApi m
apiNgramsTableCorpus cId = getTableNgramsCorpus cId
:<|> tableNgramsPut
:<|> tableNgramsPost
--{-
-- TODO Doc Table Ngrams API
type ApiNgramsTableDoc = TableNgramsApiGet
:<|> TableNgramsApiPut
:<|> TableNgramsApiPost
apiNgramsTableDoc :: ( RepoCmdM env err m apiNgramsTableDoc :: ( RepoCmdM env err m
, HasNodeError err , HasNodeError err
, HasInvalidError err , HasInvalidError err
, HasConnection env , HasConnection env
) )
=> DocId -> ServerT ApiNgramsTableDoc m => DocId -> ServerT TableNgramsApi m
apiNgramsTableDoc dId = getTableNgramsDoc dId apiNgramsTableDoc dId = getTableNgramsDoc dId
:<|> tableNgramsPut :<|> tableNgramsPut
:<|> tableNgramsPost :<|> tableNgramsPost
......
...@@ -45,7 +45,7 @@ import Data.Text (Text()) ...@@ -45,7 +45,7 @@ import Data.Text (Text())
import Data.Time (UTCTime) import Data.Time (UTCTime)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.API.Metrics import Gargantext.API.Metrics
import Gargantext.API.Ngrams (TabType(..), TableNgramsApiPut, TableNgramsApiGet, tableNgramsPut, getTableNgramsCorpus, QueryParamR) import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, apiNgramsTableCorpus, QueryParamR)
import Gargantext.API.Search ( SearchAPI, searchIn, SearchInQuery) import Gargantext.API.Search ( SearchAPI, searchIn, SearchInQuery)
import Gargantext.API.Types import Gargantext.API.Types
import Gargantext.Core.Types (Offset, Limit) import Gargantext.Core.Types (Offset, Limit)
...@@ -122,8 +122,7 @@ type NodeAPI a = Get '[JSON] (Node a) ...@@ -122,8 +122,7 @@ type NodeAPI a = Get '[JSON] (Node a)
-- TODO gather it -- TODO gather it
:<|> "table" :> TableApi :<|> "table" :> TableApi
:<|> "listGet" :> TableNgramsApiGet :<|> "ngrams" :> TableNgramsApi
:<|> "list" :> TableNgramsApiPut
:<|> "pairing" :> PairingApi :<|> "pairing" :> PairingApi
:<|> "favorites" :> FavApi :<|> "favorites" :> FavApi
...@@ -170,8 +169,7 @@ nodeAPI p uId id ...@@ -170,8 +169,7 @@ nodeAPI p uId id
-- TODO gather it -- TODO gather it
:<|> getTable id :<|> getTable id
:<|> getTableNgramsCorpus id :<|> apiNgramsTableCorpus id
:<|> tableNgramsPut
:<|> getPairing id :<|> getPairing id
-- :<|> getTableNgramsDoc id -- :<|> getTableNgramsDoc id
......
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