]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/HashedResponse.hs
[REFACT] uniforming hyperdata fields name
[gargantext.git] / src / Gargantext / API / HashedResponse.hs
1 module Gargantext.API.HashedResponse where
2
3 import Data.Aeson
4 import Data.Swagger
5 import qualified Data.Digest.Pure.MD5 as DPMD5
6 import GHC.Generics (Generic)
7 import Protolude
8
9 data HashedResponse a = HashedResponse { md5 :: Text, value :: a }
10 deriving (Generic)
11
12 instance ToSchema a => ToSchema (HashedResponse a)
13 instance ToJSON a => ToJSON (HashedResponse a) where
14 toJSON = genericToJSON defaultOptions
15
16 constructHashedResponse :: ToJSON a => a -> HashedResponse a
17 constructHashedResponse v = HashedResponse { md5 = md5', value = v }
18 where
19 md5' = show $ DPMD5.md5 $ encode v