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
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
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
9ba39267
Commit
9ba39267
authored
May 15, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API] Upload csv.
parent
85a70600
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
14 deletions
+34
-14
package.yaml
package.yaml
+1
-0
Upload.hs
src/Gargantext/API/Upload.hs
+29
-13
CSV.hs
src/Gargantext/Text/Parsers/CSV.hs
+4
-1
No files found.
package.yaml
View file @
9ba39267
...
...
@@ -162,6 +162,7 @@ library:
-
servant-swagger
-
servant-swagger-ui
-
servant-static-th
-
servant-cassava
-
serialise
-
split
-
stemmer
...
...
src/Gargantext/API/Upload.hs
View file @
9ba39267
...
...
@@ -25,17 +25,20 @@ Portability : POSIX
module
Gargantext.API.Upload
where
import
qualified
Data.Text
as
Text
import
GHC.Generics
(
Generic
)
import
Gargantext.Prelude
import
Data.Text
(
Text
)
import
Data.Aeson
import
Servant
import
Servant.Multipart
--import Servant.Mock (HasMock(mock))
import
Servant.Swagger
(
HasSwagger
(
toSwagger
))
import
qualified
Data.ByteString.Lazy
as
LBS
--
import qualified Data.ByteString.Lazy as LBS
import
Control.Monad
import
Control.Monad.IO.Class
import
Gargantext.API.Types
import
Servant.CSV.Cassava
(
CSV
'
(
..
))
--import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
--import Data.Swagger
--import Gargantext.API.Ngrams (TODO)
...
...
@@ -67,22 +70,35 @@ instance HasMock (MultipartForm Mem (MultipartData Mem) :> sub) context where
mock _ _ = undefined
-}
type
ApiUpload
=
MultipartForm
Mem
(
MultipartData
Mem
)
:>
Post
'[
J
SON
]
Integer
data
Upload
=
Upload
{
up
::
[
Text
]
}
deriving
(
Generic
)
instance
ToJSON
Upload
type
ApiUpload
=
MultipartForm
Mem
(
MultipartData
Mem
)
:>
Post
'[
J
SON
]
Text
-- MultipartData consists in textual inputs,
-- accessible through its "inputs" field, as well
-- as files, accessible through its "files" field.
upload
::
GargServer
ApiUpload
upload
multipartData
=
do
liftIO
$
do
--{-
is
<-
liftIO
$
do
putStrLn
(
"Inputs:"
::
Text
)
forM_
(
inputs
multipartData
)
$
\
input
->
putStrLn
$
(
" "
::
Text
)
<>
(
iName
input
)
<>
(
" -> "
::
Text
)
<>
(
iValue
input
)
forM_
(
files
multipartData
)
$
\
file
->
do
let
content
=
fdPayload
file
putStrLn
$
(
"Content of "
::
Text
)
<>
(
fdFileName
file
)
LBS
.
putStr
content
return
0
forM
(
inputs
multipartData
)
$
\
input
->
do
putStrLn
$
(
"iName "
::
Text
)
<>
(
iName
input
)
<>
(
"iValue "
::
Text
)
<>
(
iValue
input
)
pure
$
iName
input
--{-
_
<-
forM
(
files
multipartData
)
$
\
file
->
do
let
content
=
fdPayload
file
putStrLn
$
(
"XXX "
::
Text
)
<>
(
fdFileName
file
)
putStrLn
$
(
"YYY "
::
Text
)
<>
cs
content
--pure $ cs content
-- is <- inputs multipartData
--}
pure
$
Text
.
concat
$
map
cs
is
-------------------------------------------------------------------------------
src/Gargantext/Text/Parsers/CSV.hs
View file @
9ba39267
...
...
@@ -19,7 +19,6 @@ module Gargantext.Text.Parsers.CSV where
import
GHC.Real
(
round
)
import
GHC.IO
(
FilePath
)
import
Control.Applicative
import
Data.Char
(
ord
)
...
...
@@ -232,6 +231,10 @@ writeCsv fp (h, vs) = BL.writeFile fp $
writeDocs2Csv
::
FilePath
->
[
HyperdataDocument
]
->
IO
()
writeDocs2Csv
fp
hs
=
BL
.
writeFile
fp
$
encodeByNameWith
csvEncodeOptions
headerCsvGargV3
(
map
hyperdataDocument2csvDoc
hs
)
hyperdataDocument2csv
::
[
HyperdataDocument
]
->
BL
.
ByteString
hyperdataDocument2csv
hs
=
encodeByNameWith
csvEncodeOptions
headerCsvGargV3
(
map
hyperdataDocument2csvDoc
hs
)
------------------------------------------------------------------------
-- Hal Format
data
CsvHal
=
CsvHal
...
...
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