Skip to content

Commit

Permalink
[#500] Move HealthResponse from OR/SCS types into common so that it c…
Browse files Browse the repository at this point in the history
…an be shared between OR/SCS/Trails.
  • Loading branch information
a-stacey committed Jul 16, 2019
1 parent d648fef commit 50fbd86
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 37 deletions.
19 changes: 19 additions & 0 deletions projects/mirza-common-haskell/src/Mirza/Common/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
module Mirza.Common.Types
( EmailAddress, emailToText, Password(..) , UserId(..)
, ORKeyId(..)
, HealthResponse(..)
, EnvType(..)
, AppM(..)
, runAppM
Expand Down Expand Up @@ -85,6 +86,7 @@ import Text.Email.Validate (EmailAddress,
toByteString, validate)

import Data.Aeson
import Data.Aeson.Types

import Control.Lens
import Control.Monad.Error.Lens
Expand Down Expand Up @@ -216,6 +218,23 @@ newtype DB context error a = DB (ReaderT (Connection,context) (ExceptT error Pg)
, MonadIO -- Need to figure out if we actually want this
)


-- Health Types:
successHealthResponseText :: Text
successHealthResponseText = "Status OK"

data HealthResponse = HealthResponse
deriving (Show, Eq, Read, Generic)
instance ToSchema HealthResponse
instance ToJSON HealthResponse where
toJSON _ = toJSON successHealthResponseText
instance FromJSON HealthResponse where
parseJSON (String value)
| value == successHealthResponseText = pure HealthResponse
| otherwise = fail "Invalid health response string."
parseJSON value = typeMismatch "HealthResponse" value


-- =============================================================================
-- Classes and utilities for working with Constraints
-- =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion projects/or_scs/src/Mirza/OrgRegistry/Handlers/Health.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Mirza.OrgRegistry.Handlers.Health
) where


import Mirza.OrgRegistry.Types as ORT
import Mirza.Common.Types


-- | Currently the health check always returns success and is basically just a
Expand Down
16 changes: 0 additions & 16 deletions projects/or_scs/src/Mirza/OrgRegistry/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import Katip as K
import Network.URI (URI)

import Data.Aeson
import Data.Aeson.Types

import Data.Swagger (NamedSchema (..),
SwaggerType (..),
Expand Down Expand Up @@ -409,21 +408,6 @@ instance ToJSON KeyState where
instance ToSchema KeyState
instance ToParamSchema KeyState

-- Health Types:
successHealthResponseText :: Text
successHealthResponseText = "Status OK"

data HealthResponse = HealthResponse
deriving (Show, Eq, Read, Generic)
instance ToSchema HealthResponse
instance ToJSON HealthResponse where
toJSON _ = toJSON successHealthResponseText
instance FromJSON HealthResponse where
parseJSON (String value)
| value == successHealthResponseText = pure HealthResponse
| otherwise = fail "Invalid health response string."
parseJSON value = typeMismatch "HealthResponse" value


-- *****************************************************************************
-- Signing and Hashing Types
Expand Down
20 changes: 0 additions & 20 deletions projects/or_scs/src/Mirza/SupplyChain/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Control.Lens hiding ((.=))
import GHC.Generics (Generic)

import Data.Aeson
import Data.Aeson.Types
import qualified Data.ByteString as BS
import Data.List.NonEmpty (NonEmpty)
import Data.Pool as Pool
Expand Down Expand Up @@ -166,25 +165,6 @@ instance ToJSON EventInfo where
instance ToSchema EventInfo


-- *****************************************************************************
-- Health Types
-- *****************************************************************************

successHealthResponseText :: Text
successHealthResponseText = "Status OK"

data HealthResponse = HealthResponse
deriving (Show, Eq, Read, Generic)
instance ToSchema HealthResponse
instance ToJSON HealthResponse where
toJSON _ = toJSON successHealthResponseText
instance FromJSON HealthResponse where
parseJSON (String value)
| value == successHealthResponseText = pure HealthResponse
| otherwise = fail "Invalid health response string."
parseJSON value = typeMismatch "HealthResponse" value


-- *****************************************************************************
-- Error Types
-- *****************************************************************************
Expand Down

0 comments on commit 50fbd86

Please sign in to comment.