]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/HashedResponse.hs
[metrics] fix ServerError
[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
7 import Gargantext.Prelude
8 import qualified Gargantext.Prelude.Utils as Crypto (hash)
9 import GHC.Generics (Generic)
10
11 data HashedResponse a = HashedResponse { hash :: Text, value :: a }
12 deriving (Generic)
13
14 instance ToSchema a => ToSchema (HashedResponse a)
15 instance ToJSON a => ToJSON (HashedResponse a) where
16 toJSON = genericToJSON defaultOptions
17
18 constructHashedResponse :: ToJSON a => a -> HashedResponse a
19 constructHashedResponse v = HashedResponse { hash = Crypto.hash $ encode v, value = v }