]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/HashedResponse.hs
[REFACT] hash functions
[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 Gargantext.Prelude.Utils (hash)
8 import GHC.Generics (Generic)
9
10 data HashedResponse a = HashedResponse { md5 :: 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 { md5 = md5', value = v }
19 where
20 md5' = hash $ encode v