]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/HashedResponse.hs
[API] Link Corpus -> Annuaire. Ok
[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
18 import Gargantext.Prelude
19 import qualified Gargantext.Core.Crypto.Hash as Crypto (hash)
20 import GHC.Generics (Generic)
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
29 constructHashedResponse :: ToJSON a => a -> HashedResponse a
30 constructHashedResponse v = HashedResponse { hash = Crypto.hash $ encode v, value = v }