import Gargantext.Database.Admin.Types.Hyperdata.Contact (_cw_organization)
import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Facet
+import qualified Gargantext.Defaults as Defaults
import Gargantext.Prelude
import Gargantext.Utils.Aeson (defaultTaggedObject)
import Servant
-----------------------------------------------------------------------
data SearchType = SearchDoc | SearchContact
deriving (Generic)
-instance FromJSON SearchType
- where
- parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
-instance ToJSON SearchType
- where
- toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+instance FromJSON SearchType where
+ parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+instance ToJSON SearchType where
+ toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
instance ToSchema SearchType
instance Arbitrary SearchType where
arbitrary = elements [SearchDoc, SearchContact]
, expected :: !SearchType
}
deriving (Generic)
-instance FromJSON SearchQuery
- where
- parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
-instance ToJSON SearchQuery
- where
- toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+instance FromJSON SearchQuery where
+ parseJSON = genericParseJSON defaultOptions
+instance ToJSON SearchQuery where
+ toJSON = genericToJSON defaultOptions
instance ToSchema SearchQuery
{-
where
SearchResult { result :: !SearchResultTypes}
deriving (Generic)
-instance FromJSON SearchResult
- where
- parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+instance FromJSON SearchResult where
+ parseJSON = genericParseJSON defaultOptions
-instance ToJSON SearchResult
- where
- toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+instance ToJSON SearchResult where
+ toJSON = genericToJSON defaultOptions
instance ToSchema SearchResult
{-
| SearchResultContact { contacts :: ![Row] }
| SearchNoResult { message :: !Text }
deriving (Generic)
-instance FromJSON SearchResultTypes
- where
- parseJSON = genericParseJSON (defaultOptions { sumEncoding = defaultTaggedObject })
-instance ToJSON SearchResultTypes
- where
- toJSON = genericToJSON (defaultOptions { sumEncoding = defaultTaggedObject })
+instance FromJSON SearchResultTypes where
+ parseJSON = genericParseJSON (defaultOptions { sumEncoding = defaultTaggedObject })
+instance ToJSON SearchResultTypes where
+ toJSON = genericToJSON (defaultOptions { sumEncoding = defaultTaggedObject })
instance Arbitrary SearchResultTypes where
arbitrary = do
, _hr_language_iso2 = fromMaybe "EN" _hd_language_iso2
, _hr_page = fromMaybe 0 _hd_page
, _hr_publication_date = fromMaybe "" _hd_publication_date
- , _hr_publication_day = fromMaybe 1 _hd_publication_day
- , _hr_publication_hour = fromMaybe 1 _hd_publication_hour
- , _hr_publication_minute = fromMaybe 1 _hd_publication_minute
- , _hr_publication_month = fromMaybe 1 _hd_publication_month
- , _hr_publication_second = fromMaybe 1 _hd_publication_second
- , _hr_publication_year = fromMaybe 2020 _hd_publication_year
+ , _hr_publication_year = fromMaybe (fromIntegral Defaults.year) _hd_publication_year
+ , _hr_publication_month = fromMaybe Defaults.month _hd_publication_month
+ , _hr_publication_day = fromMaybe Defaults.day _hd_publication_day
+ , _hr_publication_hour = fromMaybe 0 _hd_publication_hour
+ , _hr_publication_minute = fromMaybe 0 _hd_publication_minute
+ , _hr_publication_second = fromMaybe 0 _hd_publication_second
, _hr_source = fromMaybe "" _hd_source
, _hr_title = fromMaybe "Title" _hd_title
, _hr_url = fromMaybe "" _hd_url
, _hr_uniqIdBdd = fromMaybe "" _hd_uniqIdBdd }
instance ToHyperdataRow HyperdataContact where
- toHyperdataRow (HyperdataContact { _hc_who = Just (ContactWho _ fn ln _ _), _hc_where = ou} ) =
+ toHyperdataRow (HyperdataContact { _hc_who = Just (ContactWho _ fn ln _ _ _), _hc_where = ou} ) =
HyperdataRowContact (fromMaybe "FirstName" fn) (fromMaybe "LastName" ln) ou'
where
ou' = maybe "CNRS" (Text.intercalate " " . _cw_organization) (head ou)