]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/HashedResponse.hs
[phylo] some small phyloexport refactoring
[gargantext.git] / src / Gargantext / API / HashedResponse.hs
1 {-|
2 Module : Gargantext.API.HashedResponse
3 Description :
4 Copyright : (c) CNRS, 2020-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 module Gargantext.API.HashedResponse where
13
14 import Data.Aeson
15 import Data.Swagger
16 import Data.Text (Text)
17 import GHC.Generics (Generic)
18
19 import Gargantext.Prelude
20 import qualified Gargantext.Prelude.Crypto.Hash as Crypto (hash)
21
22 data HashedResponse a = HashedResponse { hash :: Text, value :: a }
23 deriving (Generic)
24
25 instance ToSchema a => ToSchema (HashedResponse a)
26 instance ToJSON a => ToJSON (HashedResponse a) where
27 toJSON = genericToJSON defaultOptions
28 instance FromJSON a => FromJSON (HashedResponse a) where
29 parseJSON = genericParseJSON defaultOptions
30
31 constructHashedResponse :: ToJSON a => a -> HashedResponse a
32 constructHashedResponse v = HashedResponse { hash = Crypto.hash $ encode v, value = v }