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

[TEXT] String to Text in Servant file.

parent ca5569fb
...@@ -24,7 +24,7 @@ import Protolude ( Bool(True, False), Int, Double, Integer ...@@ -24,7 +24,7 @@ import Protolude ( Bool(True, False), Int, Double, Integer
, sum, fromIntegral, length, fmap , sum, fromIntegral, length, fmap
, takeWhile, sqrt, undefined, identity , takeWhile, sqrt, undefined, identity
, abs, maximum, minimum, return, snd, truncate , abs, maximum, minimum, return, snd, truncate
, (+), (*), (/), (-), (.), (>=), ($), (**), (^), (<), (>), (==) , (+), (*), (/), (-), (.), (>=), ($), (**), (^), (<), (>), (==), (<>)
) )
-- TODO import functions optimized in Utils.Count -- TODO import functions optimized in Utils.Count
......
...@@ -8,6 +8,8 @@ Maintainer : team@gargantext.org ...@@ -8,6 +8,8 @@ Maintainer : team@gargantext.org
Stability : experimental Stability : experimental
Portability : POSIX Portability : POSIX
Main REST API of Gargantext (both Server and Client sides)
-} -}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
...@@ -20,7 +22,8 @@ module Gargantext.Server ...@@ -20,7 +22,8 @@ module Gargantext.Server
-- ) -- )
where where
import Prelude hiding (null) import Gargantext.Prelude
import Control.Monad import Control.Monad
import Control.Monad.IO.Class import Control.Monad.IO.Class
import Data.Aeson import Data.Aeson
...@@ -30,8 +33,8 @@ import Servant ...@@ -30,8 +33,8 @@ import Servant
import Servant.Multipart import Servant.Multipart
import Database.PostgreSQL.Simple (Connection, connect) import Database.PostgreSQL.Simple (Connection, connect)
import Opaleye import Opaleye
import System.IO (FilePath) import System.IO (FilePath, putStrLn, readFile, print)
import Data.Text (Text(), pack)
import Gargantext.Types.Main (Node, NodeId) import Gargantext.Types.Main (Node, NodeId)
import Gargantext.Database.Node (getNodesWithParentId, getNode) import Gargantext.Database.Node (getNodesWithParentId, getNode)
import Gargantext.Database.Private (databaseParameters) import Gargantext.Database.Private (databaseParameters)
...@@ -43,8 +46,8 @@ type NodeAPI = Get '[JSON] (Node Value) ...@@ -43,8 +46,8 @@ type NodeAPI = Get '[JSON] (Node Value)
type API = "roots" :> Get '[JSON] [Node Value] type API = "roots" :> Get '[JSON] [Node Value]
:<|> "node" :> Capture "id" Int :> NodeAPI :<|> "node" :> Capture "id" Int :> NodeAPI
:<|> "echo" :> Capture "string" String :> Get '[JSON] String :<|> "echo" :> Capture "string" Text :> Get '[JSON] Text
:<|> "upload" :> MultipartForm MultipartData :> Post '[JSON] String :<|> "upload" :> MultipartForm MultipartData :> Post '[JSON] Text
-- :<|> "node" :> Capture "id" Int :> Get '[JSON] Node -- :<|> "node" :> Capture "id" Int :> Get '[JSON] Node
...@@ -60,7 +63,7 @@ server conn ...@@ -60,7 +63,7 @@ server conn
startGargantext :: FilePath -> IO () startGargantext :: FilePath -> IO ()
startGargantext file = do startGargantext file = do
print ("Starting server on port " ++ show port) print ("Starting server on port " <> show port)
param <- databaseParameters file param <- databaseParameters file
conn <- connect param conn <- connect param
...@@ -90,17 +93,17 @@ nodeAPI conn id ...@@ -90,17 +93,17 @@ nodeAPI conn id
-- | Upload files -- | Upload files
-- TODO Is it possible to adapt the function according to iValue input ? -- TODO Is it possible to adapt the function according to iValue input ?
upload :: MultipartData -> Handler String upload :: MultipartData -> Handler Text
upload multipartData = do upload multipartData = do
liftIO $ do liftIO $ do
putStrLn "Inputs:" putStrLn "Inputs:"
forM_ (inputs multipartData) $ \input -> forM_ (inputs multipartData) $ \input ->
putStrLn $ " " ++ show (iName input) putStrLn $ " " <> show (iName input)
++ " -> " ++ show (iValue input) <> " -> " <> show (iValue input)
forM_ (files multipartData) $ \file -> do forM_ (files multipartData) $ \file -> do
content <- readFile (fdFilePath file) content <- readFile (fdFilePath file)
putStrLn $ "Content of " ++ show (fdFileName file) putStrLn $ "Content of " <> show (fdFileName file)
++ " at " ++ fdFilePath file <> " at " <> fdFilePath file
putStrLn content putStrLn content
pure "Data loaded" pure (pack "Data loaded")
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