[json] bring back previous JSON serialization of Datafield

parent 48057eb5
Pipeline #4235 failed with stages
in 38 minutes and 52 seconds
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
module Gargantext.API.Node.Corpus.Types where module Gargantext.API.Node.Corpus.Types where
import Control.Lens hiding (elements, Empty) import Control.Lens hiding (elements, Empty)
import Control.Monad.Fail (fail)
import Control.Monad.Reader (MonadReader) import Control.Monad.Reader (MonadReader)
import Data.Aeson import Data.Aeson
import Data.Aeson.TH (deriveJSON) import Data.Aeson.TH (deriveJSON)
...@@ -11,7 +10,6 @@ import Data.Monoid (mempty) ...@@ -11,7 +10,6 @@ import Data.Monoid (mempty)
import Data.Swagger import Data.Swagger
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Test.QuickCheck import Test.QuickCheck
import qualified Data.Text as T
import qualified PUBMED.Types as PUBMED import qualified PUBMED.Types as PUBMED
import Gargantext.Prelude import Gargantext.Prelude
...@@ -62,23 +60,25 @@ data Datafield = Gargantext ...@@ -62,23 +60,25 @@ data Datafield = Gargantext
| Files | Files
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
instance FromJSON Datafield where instance FromJSON Datafield
parseJSON = withText "Datafield" $ \text -> instance ToJSON Datafield
case text of -- instance FromJSON Datafield where
"Gargantext" -- parseJSON = withText "Datafield" $ \text ->
-> pure Gargantext -- case text of
"Web" -- "Gargantext"
-> pure Web -- -> pure Gargantext
"Files" -- "Web"
-> pure Files -- -> pure Web
v -> case T.breakOnEnd " " v of -- "Files"
("External ", dbName) -- -> pure Files
-> External <$> parseJSON (String dbName) -- v -> case T.breakOnEnd " " v of
_ -> fail $ "Cannot match patterh 'External <db>' for string " <> T.unpack v -- ("External ", dbName)
-- -> External <$> parseJSON (String dbName)
-- _ -> fail $ "Cannot match patterh 'External <db>' for string " <> T.unpack v
instance ToJSON Datafield where -- instance ToJSON Datafield where
toJSON (External db) = toJSON $ "External " <> show db -- toJSON (External db) = toJSON $ "External " <> show db
toJSON s = toJSON $ show s -- toJSON s = toJSON $ show s
instance Arbitrary Datafield where instance Arbitrary Datafield where
arbitrary = oneof [pure Gargantext, pure Web, pure Files, External <$> arbitrary] arbitrary = oneof [pure Gargantext, pure Web, pure Files, External <$> arbitrary]
......
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