]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/HashedResponse.hs
[CodeType] Adding Python for reading
[gargantext.git] / src / Gargantext / API / HashedResponse.hs
1 module Gargantext.API.HashedResponse where
2
3 import Data.Aeson
4 import Data.Swagger
5 import Data.Text (Text)
6 import Gargantext.Prelude
7 import qualified Gargantext.Prelude.Utils as Crypto (hash)
8 import GHC.Generics (Generic)
9
10 data HashedResponse a = HashedResponse { hash :: Text, value :: a }
11 deriving (Generic)
12
13 instance ToSchema a => ToSchema (HashedResponse a)
14 instance ToJSON a => ToJSON (HashedResponse a) where
15 toJSON = genericToJSON defaultOptions
16
17 constructHashedResponse :: ToJSON a => a -> HashedResponse a
18 constructHashedResponse v = HashedResponse (Crypto.hash $ encode v) v