-}
-{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Text (Text)
import Data.List (replicate, null)
import Data.Aeson
-import Data.Swagger
+import Data.Swagger hiding (title, url)
import GHC.Generics (Generic)
+import Servant
+import Test.QuickCheck (elements)
+import Test.QuickCheck.Arbitrary
+
+import qualified Data.List as List
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+
import Gargantext.API.Prelude
import Gargantext.API.Node.File
import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Database.Prelude
+import Gargantext.Database.Admin.Types.Hyperdata
+import Gargantext.Database.Admin.Types.Hyperdata.CorpusField
import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Table.NodeNode (selectPublicNodes)
import Gargantext.Core.Utils.DateUtils (utc2year)
-import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Schema.Node -- (NodePoly(..))
import Gargantext.Prelude
-import Servant
-import Test.QuickCheck (elements)
-import Test.QuickCheck.Arbitrary
-
-import qualified Data.List as List
-import qualified Data.Map as Map
-import qualified Data.Set as Set
+import qualified Gargantext.Utils.Aeson as GUA
------------------------------------------------------------------------
type API = API_Home
-- http://localhost:8008/api/v1.0/node/23543/file/download<Paste>
-- http://localhost:8000/images/Gargantextuel-212x300.jpg
toPublicData :: Text -> (Node HyperdataFolder, [NodeId]) -> Maybe PublicData
-toPublicData base (n , mn) = PublicData <$> (hd ^? (_Just . hf_data . cf_title))
- <*> (hd ^? (_Just . hf_data . cf_desc ))
- <*> (Just $ url' mn) -- "images/Gargantextuel-212x300.jpg"
- <*> (Just $ url' mn)
- <*> Just (cs $ show $ utc2year (n^.node_date))
- <*> (hd ^? (_Just . hf_data . cf_query))
- <*> (hd ^? (_Just . hf_data . cf_authors))
+toPublicData base (n , mn) = do
+ title <- (hd ^? (_Just . hf_data . cf_title))
+ abstract <- (hd ^? (_Just . hf_data . cf_desc ))
+ img <- (Just $ url' mn) -- "images/Gargantextuel-212x300.jpg"
+ url <- (Just $ url' mn)
+ date <- Just (cs $ show $ utc2year (n^.node_date))
+ database <- (hd ^? (_Just . hf_data . cf_query))
+ author <- (hd ^? (_Just . hf_data . cf_authors))
+ pure $ PublicData { .. }
where
hd = head
$ filter (\(HyperdataField cd _ _) -> cd == JSON)
instance FromJSON PublicData where
- parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+ parseJSON = genericParseJSON (defaultOptions { sumEncoding = GUA.defaultTaggedObject })
instance ToJSON PublicData where
- toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
+ toJSON = genericToJSON (defaultOptions { sumEncoding = GUA.defaultTaggedObject })
instance ToSchema PublicData
instance Arbitrary PublicData where
defaultPublicData :: PublicData
defaultPublicData =
- PublicData "Title"
- (foldl (<>) "" $ replicate 100 "abstract ")
- "images/Gargantextuel-212x300.jpg"
- "https://.."
- "YY/MM/DD"
- "database"
- "Author"
+ PublicData { title = "Title"
+ , abstract = foldl (<>) "" $ replicate 100 "abstract "
+ , img = "images/Gargantextuel-212x300.jpg"
+ , url = "https://.."
+ , date = "YY/MM/DD"
+ , database = "database"
+ , author = "Author" }