Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
145
Issues
145
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
6ab0ec6a
Unverified
Commit
6ab0ec6a
authored
Feb 08, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DevEnv: revamp newDevEnv, rumCmdDev
parent
f1f4726a
Pipeline
#179
canceled with stage
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
33 deletions
+71
-33
Main.hs
bin/gargantext-import/Main.hs
+10
-9
API.hs
src/Gargantext/API.hs
+12
-9
Settings.hs
src/Gargantext/API/Settings.hs
+26
-0
Cooc.hs
src/Gargantext/Database/Cooc.hs
+3
-3
Utils.hs
src/Gargantext/Database/Utils.hs
+20
-12
No files found.
bin/gargantext-import/Main.hs
View file @
6ab0ec6a
...
...
@@ -14,35 +14,36 @@ Import a corpus binary.
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Strict #-}
module
Main
where
import
Servant
(
ServantErr
)
import
Gargantext.Prelude
import
Gargantext.Database.Flow
(
flowCorpus
)
import
Gargantext.Database.Flow
(
FlowCmdM
,
flowCorpus
)
import
Gargantext.Text.Parsers
(
FileFormat
(
CsvHalFormat
))
import
Gargantext.Database.Utils
(
Cmd
,
connectGargandb
,
runCmdDev
With
)
import
Gargantext.Database.Types.Node
(
Node
Id
)
import
Gargantext.Database.Utils
(
Cmd
,
connectGargandb
,
runCmdDev
)
import
Gargantext.Database.Types.Node
(
Corpus
Id
)
--import Gargantext.Database.Schema.User (insertUsers, gargantuaUser, simpleUser)
import
Gargantext.API.Node
()
-- instances
import
Gargantext.API.
Ngrams
(
RepoCmdM
)
import
Gargantext.API.
Settings
(
newDevEnvWith
,
DevEnv
)
import
System.Environment
(
getArgs
)
main
::
IO
()
main
=
do
[
iniPath
,
name
,
corpusPath
]
<-
getArgs
env
<-
newDevEnvWith
iniPath
{-let createUsers :: Cmd ServantErr Int64
createUsers = insertUsers [gargantuaUser,simpleUser]
_ <- runCmdDev
With iniPath
createUsers
_ <- runCmdDev
env
createUsers
-}
{- -- TODO missing repo var...
let cmd :: RepoCmdM env ServantErr m => m NodeId
let
cmd
::
FlowCmdM
DevEnv
ServantErr
m
=>
m
CorpusId
cmd
=
flowCorpus
CsvHalFormat
corpusPath
(
cs
name
)
r <- runCmdDevWith iniPath cmd
-}
r
<-
runCmdDev
env
cmd
pure
()
src/Gargantext/API.hs
View file @
6ab0ec6a
...
...
@@ -72,6 +72,7 @@ import Gargantext.Prelude
import
Gargantext.API.FrontEnd
(
FrontEndAPI
,
frontEndServer
)
import
Gargantext.API.Auth
(
AuthRequest
,
AuthResponse
,
auth
)
import
Gargantext.API.Ngrams
(
HasRepoVar
)
import
Gargantext.API.Node
(
GargServer
,
Roots
,
roots
,
NodeAPI
,
nodeAPI
...
...
@@ -83,6 +84,7 @@ import Gargantext.API.Node ( GargServer
,
HyperdataAnnuaire
)
--import Gargantext.Database.Node.Contact (HyperdataContact)
import
Gargantext.Database.Utils
(
HasConnection
)
import
Gargantext.Database.Types.Node
(
NodeId
,
CorpusId
,
AnnuaireId
)
import
Gargantext.API.Count
(
CountAPI
,
count
,
Query
)
import
Gargantext.API.Search
(
SearchAPI
,
search
,
SearchQuery
)
...
...
@@ -163,9 +165,8 @@ makeMockApp env = do
makeDevApp
::
Env
->
IO
Application
makeDevApp
env
=
do
serverApp
<-
makeApp
env
makeDevMiddleware
::
IO
Middleware
makeDevMiddleware
=
do
-- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger }
--logWare <- mkRequestLogger def { destination = RequestLogger.Logger "/tmp/logs.txt" }
...
...
@@ -192,8 +193,8 @@ makeDevApp env = do
--let warpS = Warp.setPort (8008 :: Int) -- (env^.settings.appPort)
-- $ Warp.defaultSettings
--pure (warpS, logWare
$ checkOriginAndHost $ corsMiddleware $ serverApp
)
pure
$
logStdoutDev
$
corsMiddleware
$
serverApp
--pure (warpS, logWare
. checkOriginAndHost . corsMiddleware
)
pure
$
logStdoutDev
.
corsMiddleware
---------------------------------------------------------------------
-- | API Global
...
...
@@ -276,7 +277,8 @@ type API = SwaggerFrontAPI :<|> GargAPI :<|> Get '[HTML] Html
---------------------------------------------------------------------
-- | Server declarations
server
::
Env
->
IO
(
Server
API
)
server
::
(
HasConnection
env
,
HasRepoVar
env
)
=>
env
->
IO
(
Server
API
)
server
env
=
do
-- orchestrator <- scrapyOrchestrator env
pure
$
swaggerFront
...
...
@@ -312,7 +314,7 @@ gargMock :: Server GargAPI
gargMock
=
mock
apiGarg
Proxy
---------------------------------------------------------------------
makeApp
::
E
nv
->
IO
Application
makeApp
::
(
HasConnection
env
,
HasRepoVar
env
)
=>
e
nv
->
IO
Application
makeApp
=
fmap
(
serve
api
)
.
server
appMock
::
Application
...
...
@@ -372,8 +374,9 @@ startGargantext :: PortNumber -> FilePath -> IO ()
startGargantext
port
file
=
do
env
<-
newEnv
port
file
portRouteInfo
port
app
<-
makeDevApp
env
run
port
app
app
<-
makeApp
env
mid
<-
makeDevMiddleware
run
port
$
mid
app
startGargantextMock
::
PortNumber
->
IO
()
startGargantextMock
port
=
do
...
...
src/Gargantext/API/Settings.hs
View file @
6ab0ec6a
...
...
@@ -173,3 +173,29 @@ newEnv port file = do
,
_env_scrapers
=
scrapers_env
,
_env_self_url
=
self_url
}
data
DevEnv
=
DevEnv
{
_dev_env_conn
::
!
Connection
,
_dev_env_repo_var
::
!
(
MVar
NgramsRepo
)
}
makeLenses
''
D
evEnv
instance
HasConnection
DevEnv
where
connection
=
dev_env_conn
instance
HasRepoVar
DevEnv
where
repoVar
=
dev_env_repo_var
newDevEnvWith
::
FilePath
->
IO
DevEnv
newDevEnvWith
file
=
do
param
<-
databaseParameters
file
conn
<-
connect
param
repo_var
<-
newMVar
initMockRepo
pure
$
DevEnv
{
_dev_env_conn
=
conn
,
_dev_env_repo_var
=
repo_var
}
newDevEnv
::
IO
DevEnv
newDevEnv
=
newDevEnvWith
"gargantext.ini"
src/Gargantext/Database/Cooc.hs
View file @
6ab0ec6a
...
...
@@ -20,14 +20,14 @@ module Gargantext.Database.Cooc where
import
Database.PostgreSQL.Simple.SqlQQ
import
Gargantext.Prelude
import
Gargantext.Database.Utils
(
Cmd
,
runCmdDevNoErr
,
runPGSQuery
)
import
Gargantext.Database.Utils
(
Cmd
,
HasConnection
,
runCmdDevNoErr
,
runPGSQuery
)
type
CorpusId
=
Int
type
MainListId
=
Int
type
GroupListId
=
Int
coocTest
::
IO
[(
Int
,
Int
,
Int
)]
coocTest
=
runCmdDevNoErr
$
dBcooc
421968
446602
446599
coocTest
::
HasConnection
env
=>
env
->
IO
[(
Int
,
Int
,
Int
)]
coocTest
env
=
runCmdDevNoErr
env
$
dBcooc
421968
446602
446599
dBcooc
::
CorpusId
->
MainListId
->
GroupListId
->
Cmd
err
[(
Int
,
Int
,
Int
)]
dBcooc
corpus
mainList
groupList
=
runPGSQuery
[
sql
|
...
...
src/Gargantext/Database/Utils.hs
View file @
6ab0ec6a
...
...
@@ -49,13 +49,19 @@ class HasConnection env where
instance
HasConnection
Connection
where
connection
=
identity
type
CmdM
env
err
m
=
type
CmdM
'
env
err
m
=
(
MonadReader
env
m
,
HasConnection
env
,
MonadError
err
m
,
MonadIO
m
)
type
CmdM
env
err
m
=
(
CmdM'
env
err
m
,
HasConnection
env
)
type
Cmd'
env
err
a
=
forall
m
.
CmdM'
env
err
m
=>
m
a
type
Cmd
err
a
=
forall
m
env
.
CmdM
env
err
m
=>
m
a
-- TODO: ideally there should be very few calls to this functions.
...
...
@@ -64,22 +70,24 @@ mkCmd k = do
conn
<-
view
connection
liftIO
$
k
conn
runCmd
::
Connection
->
Cmd
err
a
->
IO
(
Either
err
a
)
runCmd
conn
m
=
runExceptT
$
runReaderT
m
conn
runCmd
::
HasConnection
env
=>
env
->
Cmd'
env
err
a
->
IO
(
Either
err
a
)
runCmd
env
m
=
runExceptT
$
runReaderT
m
env
-- Use only for dev
runCmdDev
With
::
Show
err
=>
FilePath
->
Cmd
err
a
->
IO
a
runCmdDevWith
fp
f
=
do
conn
<-
connectGargandb
fp
either
(
fail
.
show
)
pure
=<<
runCmd
conn
f
runCmdDev
::
(
HasConnection
env
,
Show
err
)
=>
env
->
Cmd'
env
err
a
->
IO
a
runCmdDev
env
f
=
either
(
fail
.
show
)
pure
=<<
runCmd
env
f
-- Use only for dev
runCmdDev
::
Cmd
ServantErr
a
->
IO
a
runCmdDev
=
runCmdDevWith
"gargantext.ini"
runCmdDev
NoErr
::
HasConnection
env
=>
env
->
Cmd'
env
()
a
->
IO
a
runCmdDev
NoErr
=
runCmdDev
-- Use only for dev
runCmdDev
NoErr
::
Cmd
()
a
->
IO
a
runCmdDev
NoErr
=
runCmdDevWith
"gargantext.ini"
runCmdDev
ServantErr
::
HasConnection
env
=>
env
->
Cmd
ServantErr
a
->
IO
a
runCmdDev
ServantErr
=
runCmdDev
runOpaQuery
::
Default
FromFields
fields
haskells
=>
Select
fields
->
Cmd
err
[
haskells
]
runOpaQuery
q
=
mkCmd
$
\
c
->
runQuery
c
q
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment