HashedResponse.hs 877 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
{-|
Module      : Gargantext.API.HashedResponse
Description :
Copyright   : (c) CNRS, 2020-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

12 13 14 15
module Gargantext.API.HashedResponse where

import Data.Aeson
import Data.Swagger
16
import Gargantext.Prelude
17
import Gargantext.Prelude.Crypto.Hash qualified as Crypto (hash)
18

19
data HashedResponse a = HashedResponse { hash :: Text, value :: a }
20 21 22 23 24
  deriving (Generic)

instance ToSchema a => ToSchema (HashedResponse a)
instance ToJSON a => ToJSON (HashedResponse a) where
  toJSON = genericToJSON defaultOptions
25 26
instance FromJSON a => FromJSON (HashedResponse a) where
  parseJSON = genericParseJSON defaultOptions
27 28

constructHashedResponse :: ToJSON a => a -> HashedResponse a
29
constructHashedResponse v = HashedResponse { hash = Crypto.hash $ encode v, value = v }