Commit 32d99abb authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API] Generics for Document only (WIP)

parent 077646e2
...@@ -181,26 +181,30 @@ initialPagePath {session, nodeId, listId, query} = {session, nodeId, listId, que ...@@ -181,26 +181,30 @@ initialPagePath {session, nodeId, listId, query} = {session, nodeId, listId, que
loadPage :: PagePath -> Aff (Array DocumentsView) loadPage :: PagePath -> Aff (Array DocumentsView)
loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searchType}} = do loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searchType}} = do
let p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId) let
searchResult <- post session p $ SearchQuery {query: concat query, expected:searchType} convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
pure $ res2view searchResult convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc
where convOrderBy (T.ASC (T.ColumnName "Title")) = TitleAsc
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc convOrderBy (T.DESC (T.ColumnName "Title")) = TitleDesc
convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc convOrderBy (T.ASC (T.ColumnName "Source")) = SourceAsc
convOrderBy (T.ASC (T.ColumnName "Title")) = TitleAsc convOrderBy (T.DESC (T.ColumnName "Source")) = SourceDesc
convOrderBy (T.DESC (T.ColumnName "Title")) = TitleDesc convOrderBy _ = DateAsc -- TODO
convOrderBy (T.ASC (T.ColumnName "Source")) = SourceAsc
convOrderBy (T.DESC (T.ColumnName "Source")) = SourceDesc p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId)
convOrderBy _ = DateAsc -- TODO
SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:searchType}
pure $ case result of
res2view :: SearchResult -> Array DocumentsView SearchResultDoc {docs} -> docs2view docs
res2view (SearchResultDoc {docs}) = map toView docs SearchResultContact {contacts} -> contacts2view contacts
errMessage -> err2view errMessage
docs2view :: Array Document -> Array DocumentsView
docs2view docs = map toView docs
where where
toView :: Document -> DocumentsView toView :: Document -> DocumentsView
toView (Document { id toView ( Document { id
, created: date , created: date
, hyperdata: HyperdataDocument { authors , hyperdata: HyperdataRowDocument { authors
, title , title
, source , source
, publication_year , publication_year
...@@ -223,7 +227,7 @@ res2view (SearchResultDoc {docs}) = map toView docs ...@@ -223,7 +227,7 @@ res2view (SearchResultDoc {docs}) = map toView docs
, publication_month: fromMaybe 1 publication_month , publication_month: fromMaybe 1 publication_month
, publication_day : fromMaybe 1 publication_day , publication_day : fromMaybe 1 publication_day
} }
res2view (SearchResultContact {contacts}) = map toView contacts contacts2view contacts = map toView contacts
where where
toView :: Contact -> DocumentsView toView :: Contact -> DocumentsView
toView (Contact { id toView (Contact { id
...@@ -248,7 +252,22 @@ res2view (SearchResultContact {contacts}) = map toView contacts ...@@ -248,7 +252,22 @@ res2view (SearchResultContact {contacts}) = map toView contacts
, publication_day: 1 , publication_day: 1
} }
-- res2view (SearchNoResult {message}) = map toView contacts err2view message =
[DocumentsView { id: 1
, date: "2020-01-01"
, title : "SearchNoResult"
, source: "Source"
, score: 1
, authors: "Authors"
, category: decodeCategory 1
, pairs: []
, delete: false
, publication_year: 2020
, publication_month: 10
, publication_day: 1
}
]
......
...@@ -42,9 +42,8 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where ...@@ -42,9 +42,8 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------------------------------------------------------------------------ ------------------------------------------------------------------------
data SearchResult = SearchResultDoc { docs :: Array Document}
| SearchResultContact { contacts :: Array Contact } data SearchResult = SearchResult { result :: SearchResultTypes }
-- | SearchNoResult { message :: String }
derive instance eqSearchResult :: Eq SearchResult derive instance eqSearchResult :: Eq SearchResult
derive instance genericSearchResult :: Generic SearchResult _ derive instance genericSearchResult :: Generic SearchResult _
...@@ -55,13 +54,31 @@ instance decodeJsonSearchResult :: Argonaut.DecodeJson SearchResult where ...@@ -55,13 +54,31 @@ instance decodeJsonSearchResult :: Argonaut.DecodeJson SearchResult where
instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
data SearchResultTypes =
SearchResultContact { contacts :: Array Contact }
| SearchNoResult { message :: String }
| SearchResultDoc { docs :: Array Document}
derive instance eqSearchResultTypes :: Eq SearchResultTypes
derive instance genericSearchResultTypes :: Generic SearchResultTypes _
instance showSearchResultTypes :: Show SearchResultTypes where
show = genericShow
instance decodeJsonSearchResultTypes :: Argonaut.DecodeJson SearchResultTypes where
decodeJson = genericSumDecodeJson
instance encodeJsonSearchResultTypes :: Argonaut.EncodeJson SearchResultTypes where
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Document = data Document =
Document { id :: Int Document { id :: Int
, created :: String , created :: String
, title :: String , title :: String
, hyperdata :: HyperdataDocument , hyperdata :: HyperdataRowDocument
, category :: Int , category :: Int
, score :: Int , score :: Int
} }
...@@ -75,41 +92,43 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where ...@@ -75,41 +92,43 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where
instance encodeJsonDocument :: Argonaut.EncodeJson Document where instance encodeJsonDocument :: Argonaut.EncodeJson Document where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
-----------
------------------------------------------------------------------------ ------------------------------------------------------------------------
data HyperdataDocument = newtype HyperdataRowDocument =
HyperdataDocument { bdd :: Maybe String HyperdataRowDocument { bdd :: Maybe String
, doi :: Maybe String , doi :: Maybe String
, url :: Maybe String , url :: Maybe String
, uniqId :: Maybe String , uniqId :: Maybe String
, uniqIdBdd :: Maybe String , uniqIdBdd :: Maybe String
, page :: Maybe Int , page :: Maybe Int
, title :: Maybe String , title :: Maybe String
, authors :: Maybe String , authors :: Maybe String
, institutes :: Maybe String , institutes :: Maybe String
, source :: Maybe String , source :: Maybe String
, abstract :: Maybe String , abstract :: Maybe String
, publication_date :: Maybe String , publication_date :: Maybe String
, publication_year :: Maybe Int , publication_year :: Maybe Int
, publication_month :: Maybe Int , publication_month :: Maybe Int
, publication_day :: Maybe Int , publication_day :: Maybe Int
, publication_hour :: Maybe Int , publication_hour :: Maybe Int
, publication_minute :: Maybe Int , publication_minute :: Maybe Int
, publication_second :: Maybe Int , publication_second :: Maybe Int
, language_iso2 :: Maybe String , language_iso2 :: Maybe String
} }
derive instance eqHyperdataDocument :: Eq HyperdataDocument derive instance eqHyperdataRowDocument :: Eq HyperdataRowDocument
derive instance genericHyperdataDocument :: Generic HyperdataDocument _ derive instance genericHyperdataRowDocument :: Generic HyperdataRowDocument _
instance showHyperdataDocument :: Show HyperdataDocument where instance showHyperdataRowDocument :: Show HyperdataRowDocument where
show = genericShow show = genericShow
instance decodeJsonHyperdataDocument :: Argonaut.DecodeJson HyperdataDocument where instance decodeJsonHyperdataRowDocument :: Argonaut.DecodeJson HyperdataRowDocument where
decodeJson = genericSumDecodeJson decodeJson = genericSumDecodeJson
instance encodeJsonHyperdataDocument :: Argonaut.EncodeJson HyperdataDocument where instance encodeJsonHyperdataRowDocument :: Argonaut.EncodeJson HyperdataRowDocument where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Contact = data Contact =
Contact { id :: Int Contact { id :: Int
, created :: String , created :: String
......
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