Commit e51a41bb authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API] Search authors/contact ok

parent 0c379866
......@@ -192,7 +192,8 @@ loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searc
p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId)
SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:searchType}
--SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:searchType}
SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:SearchContact}
pure $ case result of
SearchResultDoc {docs} -> docs2view docs
SearchResultContact {contacts} -> contacts2view contacts
......@@ -230,20 +231,20 @@ docs2view docs = map toView docs
contacts2view contacts = map toView contacts
where
toView :: Contact -> DocumentsView
toView (Contact { id
, created: date
, hyperdata: HyperdataContact { who
, title
, "where": contactWhere
toView (Contact { c_id
, c_created: date
, c_hyperdata: HyperdataRowContact { firstname
, lastname
, labs
}
, score
, c_score
}
) = DocumentsView { id
) = DocumentsView { id: c_id
, date
, title : fromMaybe "Title" title
, source: fromMaybe "Source" title
, score: 1
, authors: fromMaybe "Authors" title
, title : firstname <> lastname
, source: labs
, score: c_score
, authors: labs
, category: decodeCategory 1
, pairs: []
, delete: false
......
......@@ -42,7 +42,7 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
------------------------------------------------------------------------
data SearchResult = SearchResult { result :: SearchResultTypes }
derive instance eqSearchResult :: Eq SearchResult
......@@ -55,11 +55,11 @@ instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
data SearchResultTypes =
SearchResultContact { contacts :: Array Contact }
SearchResultDoc { docs :: Array Document}
| SearchNoResult { message :: String }
| SearchResultDoc { docs :: Array Document}
| SearchResultContact { contacts :: Array Contact }
derive instance eqSearchResultTypes :: Eq SearchResultTypes
derive instance genericSearchResultTypes :: Generic SearchResultTypes _
......@@ -71,9 +71,7 @@ instance encodeJsonSearchResultTypes :: Argonaut.EncodeJson SearchResultTypes wh
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
data Document =
Document { id :: Int
, created :: String
......@@ -92,7 +90,6 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where
instance encodeJsonDocument :: Argonaut.EncodeJson Document where
encodeJson = genericSumEncodeJson
-----------
------------------------------------------------------------------------
newtype HyperdataRowDocument =
HyperdataRowDocument { bdd :: Maybe String
......@@ -128,12 +125,11 @@ instance encodeJsonHyperdataRowDocument :: Argonaut.EncodeJson HyperdataRowDocum
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
data Contact =
Contact { id :: Int
, created :: String
, hyperdata :: HyperdataContact
, score :: Int
Contact { c_id :: Int
, c_created :: String
, c_hyperdata :: HyperdataRowContact
, c_score :: Int
}
derive instance eqContact :: Eq Contact
......@@ -146,6 +142,23 @@ instance encodeJsonContact :: Argonaut.EncodeJson Contact where
encodeJson = genericSumEncodeJson
data HyperdataRowContact =
HyperdataRowContact { firstname :: String
, lastname :: String
, labs :: String
}
derive instance eqHyperdataRowContact :: Eq HyperdataRowContact
derive instance genericHyperdataRowContact :: Generic HyperdataRowContact _
instance showHyperdataRowContact :: Show HyperdataRowContact where
show = genericShow
instance decodeJsonHyperdataRowContact :: Argonaut.DecodeJson HyperdataRowContact where
decodeJson = genericSumDecodeJson
instance encodeJsonHyperdataRowContact :: Argonaut.EncodeJson HyperdataRowContact where
encodeJson = genericSumEncodeJson
data HyperdataContact =
HyperdataContact { bdd :: Maybe String
, who :: Maybe ContactWho
......@@ -166,7 +179,6 @@ instance encodeJsonHyperdataContact :: Argonaut.EncodeJson HyperdataContact wher
encodeJson = genericSumEncodeJson
-------
data ContactWho =
ContactWho { id :: Maybe String
, firstName :: Maybe String
......@@ -184,7 +196,6 @@ instance encodeJsonContactWho :: Argonaut.EncodeJson ContactWho where
encodeJson = genericSumEncodeJson
data ContactWhere =
ContactWhere { organization :: Array String
, labTeamDepts :: Array String
......@@ -224,4 +235,3 @@ instance decodeJsonContactTouch :: Argonaut.DecodeJson ContactTouch where
instance encodeJsonContactTouch :: Argonaut.EncodeJson ContactTouch where
encodeJson = genericSumEncodeJson
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment