Commit 7d5cc047 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[STATIC+SWAGGER+MOCK] startGargantextMock 8008

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