Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
19ab7c5a
Verified
Commit
19ab7c5a
authored
Sep 02, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[search] fix json serialization of search objects
This is to match the { tag | value } on the frontend.
parent
d91758bc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
39 deletions
+38
-39
Search.hs
src/Gargantext/API/Search.hs
+31
-39
Aeson.hs
src/Gargantext/Utils/Aeson.hs
+7
-0
No files found.
src/Gargantext/API/Search.hs
View file @
19ab7c5a
...
...
@@ -17,7 +17,7 @@ Count API part of Gargantext.
module
Gargantext.API.Search
where
import
Data.Aeson
import
Data.Aeson
hiding
(
defaultTaggedObject
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Swagger
hiding
(
fieldLabelModifier
,
Contact
)
import
Data.Text
(
Text
)
...
...
@@ -32,6 +32,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Contact (_cw_organization)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Query.Facet
import
Gargantext.Prelude
import
Gargantext.Utils.Aeson
(
defaultTaggedObject
)
import
Servant
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
...
...
@@ -127,19 +128,17 @@ instance Arbitrary SearchResult where
arbitrary
=
SearchResult
<$>
arbitrary
data
SearchResultTypes
=
SearchResultDoc
{
docs
::
!
[
Row
]}
data
SearchResultTypes
=
SearchResultDoc
{
docs
::
!
[
Row
]
}
|
SearchResultContact
{
contacts
::
!
[
Row
]
}
|
SearchNoResult
{
message
::
!
Text
}
deriving
(
Generic
)
instance
FromJSON
SearchResultTypes
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
})
instance
ToJSON
SearchResultTypes
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
})
instance
Arbitrary
SearchResultTypes
where
arbitrary
=
do
...
...
@@ -169,18 +168,13 @@ data Row =
,
c_annuaireId
::
!
NodeId
}
deriving
(
Generic
)
instance
FromJSON
Row
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
}
)
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
}
)
instance
ToJSON
Row
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
})
instance
Arbitrary
Row
where
arbitrary
=
arbitrary
...
...
@@ -203,47 +197,45 @@ instance ToRow FacetContact where
--------------------------------------------------------------------
data
HyperdataRow
=
HyperdataRowDocument
{
_hr_bdd
::
!
Text
,
_hr_doi
::
!
Text
,
_hr_url
::
!
Text
,
_hr_uniqId
::
!
Text
,
_hr_uniqIdBdd
::
!
Text
,
_hr_page
::
!
Int
,
_hr_title
::
!
Text
HyperdataRowDocument
{
_hr_abstract
::
!
Text
,
_hr_authors
::
!
Text
,
_hr_bdd
::
!
Text
,
_hr_doi
::
!
Text
,
_hr_institutes
::
!
Text
,
_hr_
source
::
!
Text
,
_hr_
abstract
::
!
Tex
t
,
_hr_
language_iso2
::
!
Text
,
_hr_
page
::
!
In
t
,
_hr_publication_date
::
!
Text
,
_hr_publication_year
::
!
Int
,
_hr_publication_month
::
!
Int
,
_hr_publication_day
::
!
Int
,
_hr_publication_hour
::
!
Int
,
_hr_publication_minute
::
!
Int
,
_hr_publication_month
::
!
Int
,
_hr_publication_second
::
!
Int
,
_hr_language_iso2
::
!
Text
,
_hr_publication_year
::
!
Int
,
_hr_source
::
!
Text
,
_hr_title
::
!
Text
,
_hr_url
::
!
Text
,
_hr_uniqId
::
!
Text
,
_hr_uniqIdBdd
::
!
Text
}
|
HyperdataRowContact
{
_hr_firstname
::
!
Text
,
_hr_lastname
::
!
Text
,
_hr_labs
::
!
Text
}
deriving
(
Generic
)
instance
FromJSON
HyperdataRow
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
{
sumEncoding
=
defaultTaggedObject
,
fieldLabelModifier
=
unCapitalize
.
dropPrefix
"_hr_"
,
omitNothingFields
=
False
}
)
instance
ToJSON
HyperdataRow
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
{
sumEncoding
=
defaultTaggedObject
,
fieldLabelModifier
=
unCapitalize
.
dropPrefix
"_hr_"
,
omitNothingFields
=
False
}
...
...
src/Gargantext/Utils/Aeson.hs
0 → 100644
View file @
19ab7c5a
module
Gargantext.Utils.Aeson
where
import
Data.Aeson.Types
-- this is what purescript Simple.JSON generics assumes
defaultTaggedObject
::
SumEncoding
defaultTaggedObject
=
TaggedObject
{
tagFieldName
=
"type"
,
contentsFieldName
=
"value"
}
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