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
199
Issues
199
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
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
Pipeline
#1755
failed with stage
in 6 minutes and 25 seconds
Changes
2
Pipelines
1
Hide 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.
...
@@ -17,7 +17,7 @@ Count API part of Gargantext.
module
Gargantext.API.Search
module
Gargantext.API.Search
where
where
import
Data.Aeson
import
Data.Aeson
hiding
(
defaultTaggedObject
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Swagger
hiding
(
fieldLabelModifier
,
Contact
)
import
Data.Swagger
hiding
(
fieldLabelModifier
,
Contact
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
...
@@ -32,6 +32,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Contact (_cw_organization)
...
@@ -32,6 +32,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Contact (_cw_organization)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Query.Facet
import
Gargantext.Database.Query.Facet
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Utils.Aeson
(
defaultTaggedObject
)
import
Servant
import
Servant
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
import
Test.QuickCheck.Arbitrary
...
@@ -127,19 +128,17 @@ instance Arbitrary SearchResult where
...
@@ -127,19 +128,17 @@ instance Arbitrary SearchResult where
arbitrary
=
SearchResult
<$>
arbitrary
arbitrary
=
SearchResult
<$>
arbitrary
data
SearchResultTypes
=
SearchResultDoc
{
docs
::
!
[
Row
]}
data
SearchResultTypes
=
|
SearchResultContact
{
contacts
::
!
[
Row
]
}
SearchResultDoc
{
docs
::
!
[
Row
]
}
|
SearchNoResult
{
message
::
!
Text
}
|
SearchResultContact
{
contacts
::
!
[
Row
]
}
|
SearchNoResult
{
message
::
!
Text
}
deriving
(
Generic
)
deriving
(
Generic
)
instance
FromJSON
SearchResultTypes
instance
FromJSON
SearchResultTypes
where
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
})
instance
ToJSON
SearchResultTypes
instance
ToJSON
SearchResultTypes
where
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
})
instance
Arbitrary
SearchResultTypes
where
instance
Arbitrary
SearchResultTypes
where
arbitrary
=
do
arbitrary
=
do
...
@@ -155,13 +154,13 @@ instance ToSchema SearchResultTypes where
...
@@ -155,13 +154,13 @@ instance ToSchema SearchResultTypes where
--------------------------------------------------------------------
--------------------------------------------------------------------
data
Row
=
data
Row
=
Document
{
id
::
!
NodeId
Document
{
id
::
!
NodeId
,
created
::
!
UTCTime
,
created
::
!
UTCTime
,
title
::
!
Text
,
title
::
!
Text
,
hyperdata
::
!
HyperdataRow
,
hyperdata
::
!
HyperdataRow
,
category
::
!
Int
,
category
::
!
Int
,
score
::
!
Int
,
score
::
!
Int
}
}
|
Contact
{
c_id
::
!
Int
|
Contact
{
c_id
::
!
Int
,
c_created
::
!
UTCTime
,
c_created
::
!
UTCTime
,
c_hyperdata
::
!
HyperdataRow
,
c_hyperdata
::
!
HyperdataRow
...
@@ -169,18 +168,13 @@ data Row =
...
@@ -169,18 +168,13 @@ data Row =
,
c_annuaireId
::
!
NodeId
,
c_annuaireId
::
!
NodeId
}
}
deriving
(
Generic
)
deriving
(
Generic
)
instance
FromJSON
Row
instance
FromJSON
Row
where
where
parseJSON
=
genericParseJSON
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
}
)
}
)
instance
ToJSON
Row
instance
ToJSON
Row
where
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
defaultTaggedObject
})
instance
Arbitrary
Row
where
instance
Arbitrary
Row
where
arbitrary
=
arbitrary
arbitrary
=
arbitrary
...
@@ -203,47 +197,45 @@ instance ToRow FacetContact where
...
@@ -203,47 +197,45 @@ instance ToRow FacetContact where
--------------------------------------------------------------------
--------------------------------------------------------------------
data
HyperdataRow
=
data
HyperdataRow
=
HyperdataRowDocument
{
_hr_bdd
::
!
Text
HyperdataRowDocument
{
_hr_abstract
::
!
Text
,
_hr_doi
::
!
Text
,
_hr_url
::
!
Text
,
_hr_uniqId
::
!
Text
,
_hr_uniqIdBdd
::
!
Text
,
_hr_page
::
!
Int
,
_hr_title
::
!
Text
,
_hr_authors
::
!
Text
,
_hr_authors
::
!
Text
,
_hr_bdd
::
!
Text
,
_hr_doi
::
!
Text
,
_hr_institutes
::
!
Text
,
_hr_institutes
::
!
Text
,
_hr_
source
::
!
Text
,
_hr_
language_iso2
::
!
Text
,
_hr_
abstract
::
!
Tex
t
,
_hr_
page
::
!
In
t
,
_hr_publication_date
::
!
Text
,
_hr_publication_date
::
!
Text
,
_hr_publication_year
::
!
Int
,
_hr_publication_month
::
!
Int
,
_hr_publication_day
::
!
Int
,
_hr_publication_day
::
!
Int
,
_hr_publication_hour
::
!
Int
,
_hr_publication_hour
::
!
Int
,
_hr_publication_minute
::
!
Int
,
_hr_publication_minute
::
!
Int
,
_hr_publication_month
::
!
Int
,
_hr_publication_second
::
!
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
|
HyperdataRowContact
{
_hr_firstname
::
!
Text
,
_hr_lastname
::
!
Text
,
_hr_lastname
::
!
Text
,
_hr_labs
::
!
Text
,
_hr_labs
::
!
Text
}
}
deriving
(
Generic
)
deriving
(
Generic
)
instance
FromJSON
HyperdataRow
instance
FromJSON
HyperdataRow
where
where
parseJSON
=
genericParseJSON
parseJSON
=
genericParseJSON
(
defaultOptions
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
{
sumEncoding
=
defaultTaggedObject
,
fieldLabelModifier
=
unCapitalize
.
dropPrefix
"_hr_"
,
fieldLabelModifier
=
unCapitalize
.
dropPrefix
"_hr_"
,
omitNothingFields
=
False
,
omitNothingFields
=
False
}
}
)
)
instance
ToJSON
HyperdataRow
instance
ToJSON
HyperdataRow
where
where
toJSON
=
genericToJSON
toJSON
=
genericToJSON
(
defaultOptions
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
{
sumEncoding
=
defaultTaggedObject
,
fieldLabelModifier
=
unCapitalize
.
dropPrefix
"_hr_"
,
fieldLabelModifier
=
unCapitalize
.
dropPrefix
"_hr_"
,
omitNothingFields
=
False
,
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