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 ...@@ -192,7 +192,8 @@ loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searc
p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId) 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 pure $ case result of
SearchResultDoc {docs} -> docs2view docs SearchResultDoc {docs} -> docs2view docs
SearchResultContact {contacts} -> contacts2view contacts SearchResultContact {contacts} -> contacts2view contacts
...@@ -230,20 +231,20 @@ docs2view docs = map toView docs ...@@ -230,20 +231,20 @@ docs2view docs = map toView docs
contacts2view contacts = map toView contacts contacts2view contacts = map toView contacts
where where
toView :: Contact -> DocumentsView toView :: Contact -> DocumentsView
toView (Contact { id toView (Contact { c_id
, created: date , c_created: date
, hyperdata: HyperdataContact { who , c_hyperdata: HyperdataRowContact { firstname
, title , lastname
, "where": contactWhere , labs
} }
, score , c_score
} }
) = DocumentsView { id ) = DocumentsView { id: c_id
, date , date
, title : fromMaybe "Title" title , title : firstname <> lastname
, source: fromMaybe "Source" title , source: labs
, score: 1 , score: c_score
, authors: fromMaybe "Authors" title , authors: labs
, category: decodeCategory 1 , category: decodeCategory 1
, pairs: [] , pairs: []
, delete: false , delete: false
......
...@@ -42,7 +42,7 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where ...@@ -42,7 +42,7 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------
data SearchResult = SearchResult { result :: SearchResultTypes } data SearchResult = SearchResult { result :: SearchResultTypes }
derive instance eqSearchResult :: Eq SearchResult derive instance eqSearchResult :: Eq SearchResult
...@@ -55,11 +55,11 @@ instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where ...@@ -55,11 +55,11 @@ instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
data SearchResultTypes = data SearchResultTypes =
SearchResultContact { contacts :: Array Contact } SearchResultDoc { docs :: Array Document}
| SearchNoResult { message :: String } | SearchNoResult { message :: String }
| SearchResultDoc { docs :: Array Document} | SearchResultContact { contacts :: Array Contact }
derive instance eqSearchResultTypes :: Eq SearchResultTypes derive instance eqSearchResultTypes :: Eq SearchResultTypes
derive instance genericSearchResultTypes :: Generic SearchResultTypes _ derive instance genericSearchResultTypes :: Generic SearchResultTypes _
...@@ -71,9 +71,7 @@ instance encodeJsonSearchResultTypes :: Argonaut.EncodeJson SearchResultTypes wh ...@@ -71,9 +71,7 @@ instance encodeJsonSearchResultTypes :: Argonaut.EncodeJson SearchResultTypes wh
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Document = data Document =
Document { id :: Int Document { id :: Int
, created :: String , created :: String
...@@ -92,7 +90,6 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where ...@@ -92,7 +90,6 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where
instance encodeJsonDocument :: Argonaut.EncodeJson Document where instance encodeJsonDocument :: Argonaut.EncodeJson Document where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
-----------
------------------------------------------------------------------------ ------------------------------------------------------------------------
newtype HyperdataRowDocument = newtype HyperdataRowDocument =
HyperdataRowDocument { bdd :: Maybe String HyperdataRowDocument { bdd :: Maybe String
...@@ -128,12 +125,11 @@ instance encodeJsonHyperdataRowDocument :: Argonaut.EncodeJson HyperdataRowDocum ...@@ -128,12 +125,11 @@ instance encodeJsonHyperdataRowDocument :: Argonaut.EncodeJson HyperdataRowDocum
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Contact = data Contact =
Contact { id :: Int Contact { c_id :: Int
, created :: String , c_created :: String
, hyperdata :: HyperdataContact , c_hyperdata :: HyperdataRowContact
, score :: Int , c_score :: Int
} }
derive instance eqContact :: Eq Contact derive instance eqContact :: Eq Contact
...@@ -146,6 +142,23 @@ instance encodeJsonContact :: Argonaut.EncodeJson Contact where ...@@ -146,6 +142,23 @@ instance encodeJsonContact :: Argonaut.EncodeJson Contact where
encodeJson = genericSumEncodeJson 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 = data HyperdataContact =
HyperdataContact { bdd :: Maybe String HyperdataContact { bdd :: Maybe String
, who :: Maybe ContactWho , who :: Maybe ContactWho
...@@ -166,7 +179,6 @@ instance encodeJsonHyperdataContact :: Argonaut.EncodeJson HyperdataContact wher ...@@ -166,7 +179,6 @@ instance encodeJsonHyperdataContact :: Argonaut.EncodeJson HyperdataContact wher
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------- -------
data ContactWho = data ContactWho =
ContactWho { id :: Maybe String ContactWho { id :: Maybe String
, firstName :: Maybe String , firstName :: Maybe String
...@@ -184,7 +196,6 @@ instance encodeJsonContactWho :: Argonaut.EncodeJson ContactWho where ...@@ -184,7 +196,6 @@ instance encodeJsonContactWho :: Argonaut.EncodeJson ContactWho where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
data ContactWhere = data ContactWhere =
ContactWhere { organization :: Array String ContactWhere { organization :: Array String
, labTeamDepts :: Array String , labTeamDepts :: Array String
...@@ -224,4 +235,3 @@ instance decodeJsonContactTouch :: Argonaut.DecodeJson ContactTouch where ...@@ -224,4 +235,3 @@ instance decodeJsonContactTouch :: Argonaut.DecodeJson ContactTouch where
instance encodeJsonContactTouch :: Argonaut.EncodeJson ContactTouch where instance encodeJsonContactTouch :: Argonaut.EncodeJson ContactTouch where
encodeJson = genericSumEncodeJson 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