import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
-import Gargantext.API.Admin.Auth (withAccess, PathId(..))
+import Gargantext.API.Admin.Auth.Types (PathId(..))
+import Gargantext.API.Admin.Auth (withAccess)
import Gargantext.API.Metrics
-import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, apiNgramsTableCorpus)
+import Gargantext.API.Ngrams (TableNgramsApi, apiNgramsTableCorpus)
+import Gargantext.API.Ngrams.Types (TabType(..))
import Gargantext.API.Node.File
import Gargantext.API.Node.New
import Gargantext.API.Prelude
import Gargantext.Database.Query.Table.NodeNode
import Gargantext.Database.Query.Tree (tree, TreeMode(..))
import Gargantext.Prelude
-import Gargantext.Viz.Phylo.API (PhyloAPI, phyloAPI)
+import Gargantext.Core.Viz.Phylo.API (PhyloAPI, phyloAPI)
import qualified Gargantext.API.Node.Share as Share
import qualified Gargantext.API.Node.Update as Update
import qualified Gargantext.API.Search as Search
import qualified Gargantext.Database.Query.Table.Node.Update as U (update, Update(..))
{-
-import qualified Gargantext.Text.List.Learn as Learn
+import qualified Gargantext.Core.Text.List.Learn as Learn
import qualified Data.Vector as Vec
--}
:<|> "ngrams" :> TableNgramsApi
:<|> "category" :> CatApi
+ :<|> "score" :> ScoreApi
:<|> "search" :> (Search.API Search.SearchResult)
:<|> "share" :> Share.API
:<|> "unpublish" :> Share.Unpublish
:<|> "file" :> FileApi
+ :<|> "async" :> FileAsyncApi
-- TODO-ACCESS: check userId CanRenameNode nodeId
-- TODO-EVENTS: NodeRenamed RenameNode or re-use some more general NodeEdited...
-- TODO gather it
:<|> tableApi id'
:<|> apiNgramsTableCorpus id'
-
+
:<|> catApi id'
+ :<|> scoreApi id'
:<|> Search.api id'
- :<|> Share.api id'
+ :<|> Share.api (RootId $ NodeId uId) id'
-- Pairing Tools
:<|> pairWith id'
:<|> pairs id'
:<|> getPair id'
+ -- VIZ
:<|> scatterApi id'
:<|> chartApi id'
:<|> pieApi id'
:<|> Share.unPublish id'
:<|> fileApi uId id'
+ :<|> fileAsyncApi uId id'
------------------------------------------------------------------------
putCat :: CorpusId -> NodesToCategory -> Cmd err [Int]
putCat cId cs' = nodeNodesCategory $ map (\n -> (cId, n, ntc_category cs')) (ntc_nodesId cs')
+------------------------------------------------------------------------
+type ScoreApi = Summary " To Score NodeNodes"
+ :> ReqBody '[JSON] NodesToScore
+ :> Put '[JSON] [Int]
+
+data NodesToScore = NodesToScore { nts_nodesId :: [NodeId]
+ , nts_score :: Int
+ }
+ deriving (Generic)
+
+-- TODO unPrefix "ntc_" FromJSON, ToJSON, ToSchema, adapt frontend.
+instance FromJSON NodesToScore
+instance ToJSON NodesToScore
+instance ToSchema NodesToScore
+
+scoreApi :: CorpusId -> GargServer ScoreApi
+scoreApi = putScore
+ where
+ putScore :: CorpusId -> NodesToScore -> Cmd err [Int]
+ putScore cId cs' = nodeNodesScore $ map (\n -> (cId, n, nts_score cs')) (nts_nodesId cs')
+
------------------------------------------------------------------------
-- TODO adapt FacetDoc -> ListDoc (and add type of document as column)
-- Pairing utilities to move elsewhere
------------------------------------------------------------------------
-type TreeAPI = QueryParams "type" NodeType :> Get '[JSON] (Tree NodeTree)
+type TreeAPI = QueryParams "type" NodeType
+ :> Get '[JSON] (Tree NodeTree)
+ :<|> "first-level"
+ :> QueryParams "type" NodeType
+ :> Get '[JSON] (Tree NodeTree)
treeAPI :: NodeId -> GargServer TreeAPI
-treeAPI = tree Advanced
+treeAPI id = tree TreeAdvanced id
+ :<|> tree TreeFirstLevel id
------------------------------------------------------------------------
-- | TODO Check if the name is less than 255 char