Commit b7355306 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[WIP] Starting query Garg for a Hello Word.

parent 5897de6c
Pipeline #813 failed with stage
......@@ -406,8 +406,8 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid))
-- TODO access
-- :<|> addUpload
-- :<|> (\corpus -> addWithQuery corpus :<|> addWithFile corpus)
:<|> addCorpusWithForm (UserDBId uid) -- "user1"
:<|> addCorpusWithQuery
:<|> addCorpusWithForm (UserDBId uid)
:<|> addCorpusWithQuery (RootId uid)
:<|> addAnnuaireWithForm
-- :<|> New.api uid -- TODO-SECURITY
......@@ -416,16 +416,10 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid))
:<|> waitAPI
{-
addUpload :: GargServer New.Upload
addUpload cId = (serveJobsAPI $ JobFunction (\i log -> New.addToCorpusJobFunction cid i (liftBase . log)))
:<|> (serveJobsAPI $ JobFunction (\i log -> New.addToCorpusWithForm cid i (liftBase . log)))
--}
addCorpusWithQuery :: GargServer New.AddWithQuery
addCorpusWithQuery cid =
addCorpusWithQuery :: User -> GargServer New.AddWithQuery
addCorpusWithQuery user cid =
serveJobsAPI $
JobFunction (\i log -> New.addToCorpusJobFunction cid i (liftBase . log))
JobFunction (\i log -> New.addToCorpusWithQuery user cid i (liftBase . log))
addWithFile :: GargServer New.AddWithFile
addWithFile cid i f =
......
......@@ -82,7 +82,7 @@ type Api = PostApi
type PostApi = Summary "New Corpus endpoint"
:> ReqBody '[JSON] Query
:> Post '[JSON] CorpusId
:> Post '[JSON] CorpusId
type GetApi = Get '[JSON] ApiInfo
-- | TODO manage several apis
......@@ -182,18 +182,26 @@ type AddWithForm = Summary "Add with FormUrlEncoded to corpus endpoint"
------------------------------------------------------------------------
-- TODO WithQuery also has a corpus id
addToCorpusJobFunction :: FlowCmdM env err m
=> CorpusId
addToCorpusWithQuery :: FlowCmdM env err m
=> User
-> CorpusId
-> WithQuery
-> (ScraperStatus -> m ())
-> m ScraperStatus
addToCorpusJobFunction _cid (WithQuery _q _dbs _l) logStatus = do
addToCorpusWithQuery u cid (WithQuery q _dbs l) logStatus = do
-- TODO ...
logStatus ScraperStatus { _scst_succeeded = Just 10
, _scst_failed = Just 2
, _scst_remaining = Just 138
, _scst_events = Just []
}
printDebug "addToCorpusWithQuery" cid
-- TODO add cid
-- TODO if cid is folder -> create Corpus
-- if cid is corpus -> add to corpus
-- if cid is root -> create corpus in Private
cids <- flowCorpusSearchInDatabase u (maybe EN identity l) q
printDebug "corpus id" cids
-- TODO ...
pure ScraperStatus { _scst_succeeded = Just 137
, _scst_failed = Just 13
......
......@@ -20,10 +20,11 @@ module Gargantext.Core.Types.Individu
import Gargantext.Prelude hiding (reverse)
import Data.Text (Text, pack, reverse)
import Gargantext.Database.Types.Node (NodeId)
type UserId = Int
data User = UserDBId UserId | UserName Text
data User = UserDBId UserId | UserName Text | RootId NodeId
deriving (Eq)
type Username = Text
......
......@@ -213,9 +213,9 @@ flowCorpusUser :: (FlowCmdM env err m, MkCorpus c)
-> Maybe c
-> [NodeId]
-> m CorpusId
flowCorpusUser l userName corpusName ctype ids = do
flowCorpusUser l user corpusName ctype ids = do
-- User Flow
(userId, _rootId, userCorpusId) <- getOrMk_RootWithCorpus userName corpusName ctype
(userId, _rootId, userCorpusId) <- getOrMk_RootWithCorpus user corpusName ctype
listId <- getOrMkList userCorpusId userId
_cooc <- mkNode NodeListCooc listId userId
-- TODO: check if present already, ignore
......@@ -337,9 +337,9 @@ getOrMk_RootWithCorpus :: (HasNodeError err, MkCorpus a)
-> Either CorpusName [CorpusId]
-> Maybe a
-> Cmd err (UserId, RootId, CorpusId)
getOrMk_RootWithCorpus username cName c = do
(userId, rootId) <- getOrMkRoot username
corpusId'' <- if username == UserName userMaster
getOrMk_RootWithCorpus user cName c = do
(userId, rootId) <- getOrMkRoot user
corpusId'' <- if user == UserName userMaster
then do
ns <- getCorporaWithParentId rootId
pure $ map _node_id ns
......
......@@ -179,6 +179,9 @@ getUserId :: HasNodeError err
=> User
-> Cmd err UserId
getUserId (UserDBId uid) = pure uid
getUserId (RootId rid) = do
n <- getNode rid
pure $ _node_userId n
getUserId (UserName u ) = do
muser <- getUser u
case muser of
......
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