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

[STATIC+SWAGGER+MOCK] startGargantextMock 8008

parent 69293cfc
......@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: 40e4da714abaf501251279c2ed061b50ad5e31f7e99e84defabf222a04998a2e
-- hash: 4e7c51f92304a8a22c00c60b641f336bcfa0c3994bd4beac6f2e9eafa90c408a
name: gargantext
version: 0.1.0.0
......@@ -58,6 +58,7 @@ library
other-modules:
Gargantext.API.Count
Gargantext.API.Node
Gargantext.API.Swagger
Gargantext.Database.Queries
Gargantext.Utils
Paths_gargantext
......
......@@ -45,7 +45,7 @@ import Control.Lens
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy.Char8 as BL8
import Data.Swagger
import Data.Text (Text)
import Data.Text (Text, pack)
--import qualified Data.Set as Set
import Database.PostgreSQL.Simple (Connection, connect)
......@@ -54,14 +54,12 @@ import Network.Wai
import Network.Wai.Handler.Warp
import Servant
-- import Servant.Mock (mock)
import Servant.Mock (mock)
import Servant.Swagger
import Servant.Swagger.UI
import Servant.Static.TH (createApiAndServerDecs)
-- import Servant.API.Stream
-- import Gargantext.API.Auth
import Gargantext.API.Node ( Roots , roots
, NodeAPI , nodeAPI
, NodesAPI , nodesAPI
......@@ -70,13 +68,8 @@ import Gargantext.API.Count ( CountAPI, count, Query)
import Gargantext.Database.Utils (databaseParameters)
---------------------------------------------------------------------
---------------------------------------------------------------------
type PortNumber = Int
---------------------------------------------------------------------
---------------------------------------------------------------------
-- | API Global
......@@ -116,26 +109,41 @@ type GargAPI = "user" :> Summary "First user endpoint"
-- | Serve front end files
$(createApiAndServerDecs "FrontEndAPI" "frontEndServer" "frontEnd")
type API = SwaggerAPI :<|> FrontEndAPI :<|> GargAPI
type SwaggerFrontAPI = SwaggerAPI :<|> FrontEndAPI
type API = SwaggerFrontAPI :<|> GargAPI
---------------------------------------------------------------------
-- | Server declaration
server :: Connection -> Server API
server conn = schemaUiServer swaggerDoc
:<|> frontEndServer
server conn = swaggerFront
:<|> roots conn
:<|> nodeAPI conn
:<|> nodeAPI conn
:<|> nodesAPI conn
:<|> count
---------------------------------------------------------------------
swaggerFront :: Server SwaggerFrontAPI
swaggerFront = schemaUiServer swaggerDoc
:<|> frontEndServer
gargMock :: Server GargAPI
gargMock = mock apiGarg Proxy
---------------------------------------------------------------------
app :: Connection -> Application
app = serve api . server
appMock :: Application
appMock = serve api (swaggerFront :<|> gargMock)
---------------------------------------------------------------------
api :: Proxy API
api = Proxy
apiGarg :: Proxy GargAPI
apiGarg = Proxy
---------------------------------------------------------------------
schemaUiServer :: (Server api ~ Handler Swagger)
......@@ -181,19 +189,17 @@ startGargantext port file = do
print ("http://localhost:" <> show port)
param <- databaseParameters file
conn <- connect param
run port ( app conn )
--
--startGargantextMock :: PortNumber -> IO ()
--startGargantextMock port = do
-- print (pack "Starting Mock server")
-- print (pack $ "curl "
-- <> "-H \"content-type: application/json"
-- <> "-d \'{\"query_query\":\"query\"}\' "
-- <> "-v http://localhost:"
-- <> show port
-- <>"/count"
-- )
-- run port ( serve api $ mock api Proxy )
run port (app conn)
startGargantextMock :: PortNumber -> IO ()
startGargantextMock port = do
print (pack "Starting Mock server")
print (pack $ "curl "
<> "-H \"content-type: application/json"
<> "-d \'{\"query_query\":\"query\"}\' "
<> "-v http://localhost:"
<> show port
<>"/count"
)
run port appMock
......@@ -49,6 +49,7 @@ import Gargantext.Database.Facet (FacetDoc, getDocFacet)
-- | Node API Types management
type Roots = Get '[JSON] [Node HyperdataDocument]
:<|> Post '[JSON] Int
:<|> Put '[JSON] Int
:<|> Delete '[JSON] Int
type NodesAPI = Delete '[JSON] Int
......@@ -56,7 +57,8 @@ type NodesAPI = Delete '[JSON] Int
type NodeAPI = Get '[JSON] (Node HyperdataDocument)
:<|> Delete '[JSON] Int
:<|> "children" :> QueryParam "type" NodeType
:<|> "children" :> Summary " Summary children"
:> QueryParam "type" NodeType
:> QueryParam "offset" Int
:> QueryParam "limit" Int
:> Get '[JSON] [Node HyperdataDocument]
......@@ -83,6 +85,7 @@ roots :: Connection -> Server Roots
roots conn = liftIO (putStrLn "Log Needed" >> getNodesWithParentId conn 0 Nothing)
:<|> pure (panic "not implemented yet")
:<|> pure (panic "not implemented yet")
:<|> pure (panic "not implemented yet")
nodeAPI :: Connection -> NodeId -> Server NodeAPI
nodeAPI conn id = liftIO (putStrLn "getNode" >> getNode conn 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