import Control.Lens (makeLenses)
import Data.Aeson.TH (deriveJSON)
+import Data.Swagger (ToSchema(..), genericDeclareNamedSchema)
import Data.Text (Text)
import Data.Time (UTCTime)
import Database.PostgreSQL.Simple.FromField (FromField, fromField)
import GHC.Generics (Generic)
-import Gargantext.Core.Utils.Prefix (unPrefix)
-import Gargantext.Database.Node (NodeWrite', AnnuaireId, UserId, Name, node)
-import Gargantext.Database.Types.Node (Node,Hyperdata,NodeType(..))
+import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
+import Gargantext.Core.Types (Name)
+import Gargantext.Database.Schema.Node (NodeWrite, node)
+import Gargantext.Database.Types.Node (Node,Hyperdata,NodeType(..), UserId, AnnuaireId)
import Gargantext.Database.Utils (fromField')
import Gargantext.Prelude
import Opaleye (QueryRunnerColumnDefault, queryRunnerColumnDefault, PGJsonb, fieldQueryRunnerColumn)
+import Test.QuickCheck (elements)
+import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
------------------------------------------------------------------------
type NodeContact = Node HyperdataContact
data HyperdataContact =
- HyperdataContact { _hc_who :: Maybe ContactWho
- , _hc_where :: Maybe [ContactWhere]
- , _hc_metaData :: Maybe ContactMetaData
+ HyperdataContact { _hc_bdd :: Maybe Text -- ID of Database source
+ , _hc_who :: Maybe ContactWho
+ , _hc_where :: [ContactWhere]
+ , _hc_title :: Maybe Text -- TODO remove (only demo)
+ , _hc_source :: Maybe Text -- TODO remove (only demo)
+ , _hc_lastValidation :: Maybe Text
+ , _hc_uniqIdBdd :: Maybe Text
+ , _hc_uniqId :: Maybe Text
} deriving (Eq, Show, Generic)
+-- TOD0 contact metadata (Type is too flat)
data ContactMetaData =
ContactMetaData { _cm_bdd :: Maybe Text
, _cm_lastValidation :: Maybe Text
- , _cm_uniqIdBdd :: Maybe Text
- , _cm_uniqId :: Maybe Text
} deriving (Eq, Show, Generic)
arbitraryHyperdataContact :: HyperdataContact
-arbitraryHyperdataContact = HyperdataContact Nothing Nothing Nothing
+arbitraryHyperdataContact = HyperdataContact Nothing Nothing []
+ Nothing Nothing Nothing
+ Nothing Nothing
data ContactWho =
ContactWho { _cw_id :: Maybe Text
, _cw_firstName :: Maybe Text
, _cw_lastName :: Maybe Text
- , _cw_keywords :: Maybe [Text]
- , _cw_freetags :: Maybe [Text]
+ , _cw_keywords :: [Text]
+ , _cw_freetags :: [Text]
} deriving (Eq, Show, Generic)
data ContactWhere =
- ContactWhere { _cw_organization :: Maybe [Text]
- , _cw_labTeamDepts :: Maybe [Text]
-
+ ContactWhere { _cw_organization :: [Text]
+ , _cw_labTeamDepts :: [Text]
+
, _cw_role :: Maybe Text
-
+
, _cw_office :: Maybe Text
, _cw_country :: Maybe Text
, _cw_city :: Maybe Text
-
+
, _cw_touch :: Maybe ContactTouch
-
+
, _cw_entry :: Maybe UTCTime
, _cw_exit :: Maybe UTCTime
} deriving (Eq, Show, Generic)
nodeContactW :: Maybe Name -> Maybe HyperdataContact
- -> AnnuaireId -> UserId -> NodeWrite'
+ -> AnnuaireId -> UserId -> NodeWrite
nodeContactW maybeName maybeContact aId =
node NodeContact name contact (Just aId)
where
contact = maybe arbitraryHyperdataContact identity maybeContact
--- | Main instances of Contact
+-- | ToSchema instances
+instance ToSchema HyperdataContact where
+ declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_hc_")
+instance ToSchema ContactWho where
+ declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_cw_")
+instance ToSchema ContactWhere where
+ declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_cw_")
+instance ToSchema ContactTouch where
+ declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_ct_")
+instance ToSchema ContactMetaData where
+ declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_cm_")
+
+-- | Arbitrary instances
+instance Arbitrary HyperdataContact where
+ arbitrary = elements [HyperdataContact Nothing Nothing [] Nothing Nothing Nothing Nothing Nothing]
-- | Specific Gargantext instance
instance Hyperdata HyperdataContact