From 4ff1ea291c266c68acfd662b7439d5c2061907ea Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 10 Aug 2020 15:02:05 +0100 Subject: Drop support for ServantT transformer type for server After burning a few hours wrestling with the type system, I decided to revert to the simpler `Server API` type instead of the `ServantT` transformer type. The problem is that I couldn't write a MonadError instance for `RIO Context`, which is my `AppM` (i.e. application monad). Using `throwIO` in the server handlers results in 500 errors, which is not what I wanted. I'm still pretty fuzzy about what's happening; I now know that exception handling in Haskell is pretty gnaryly. I may revisit this at a later time when my knowledge is more extensive. For now: time to fry bigger fish. An easier abstract is for me to pass `T.Context` into `server` as an argument, which after all is what a Reader does. TL;DR: - Read server, client ports from .envrc - Define a top-level Failure type (empty for now) - Define a top-level Success type - Define App as RIO Context (Either Failure Success) --- .../sandbox/learnpianochords/src/server/Types.hs | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'website/sandbox/learnpianochords/src/server/Types.hs') diff --git a/website/sandbox/learnpianochords/src/server/Types.hs b/website/sandbox/learnpianochords/src/server/Types.hs index a9e6661f6153..2303a752e4ad 100644 --- a/website/sandbox/learnpianochords/src/server/Types.hs +++ b/website/sandbox/learnpianochords/src/server/Types.hs @@ -9,11 +9,15 @@ import System.Envy (FromEnv, fromEnv, env) -- | Read from .envrc data Env = Env { envGoogleClientID :: !String + , envServerPort :: !Int + , envClientPort :: !Int } deriving (Eq, Show) instance FromEnv Env where fromEnv _ = do envGoogleClientID <- env "GOOGLE_CLIENT_ID" + envServerPort <- env "SERVER_PORT" + envClientPort <- env "CLIENT_PORT" pure Env {..} -- | Application context: a combination of Env and additional values. @@ -23,8 +27,18 @@ data Context = Context , contextClientPort :: !Int } --- | Type synonym for my application monad. -type App = RIO Context +-- | Top-level except for our application, as RIO recommends defining. +type Failure = () + +-- | When our app executes along the "happy path" this is the type of result it +-- produces. +type Success = () + +-- | This is our application monad. +type AppM = RIO Context + +-- | The concrete type of our application. +type App = AppM (Either Failure Success) data VerifyGoogleSignInRequest = VerifyGoogleSignInRequest { idToken :: !Text @@ -34,3 +48,28 @@ instance FromJSON VerifyGoogleSignInRequest where parseJSON = withObject "" $ \x -> do idToken <- x .: "idToken" pure VerifyGoogleSignInRequest{..} + +data GoogleLinkedAccount = GoogleLinkedAccount + { + -- { googleLinkedAccountUUID :: UUID + -- , googleLinkedAccountEmail :: Email + -- , googleLinkedAccountTsCreated :: Timestamp + googleLinkedAccountGivenName :: !(Maybe Text) + , googleLinkedAccountFamilyName :: !(Maybe Text) + , googleLinkedAccountFullName :: !(Maybe Text) + -- , googleLinkedAccountPictureURL :: URL + -- , googleLinkedAccountLocale :: Maybe Locale + } deriving (Eq, Show) + +data PayingCustomer = PayingCustomer + { + -- { payingCustomerAccountUUID :: UUID + -- , payingCustomerTsCreated :: Timestamp + } deriving (Eq, Show) + +data Session = Session + { + -- { sessionUUID :: UUID + -- , sessionAccountUUID :: UUID + -- , sessionTsCreated :: Timestamp + } deriving (Eq, Show) -- cgit 1.4.1