about summary refs log tree commit diff
path: root/website/sandbox/learnpianochords/src/server/Types.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-10T14·02+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-10T14·02+0100
commit4ff1ea291c266c68acfd662b7439d5c2061907ea (patch)
treeb019dcc69bbf4964b1964650f1f4e66bbed49cac /website/sandbox/learnpianochords/src/server/Types.hs
parentf61ed25755da89f6068efb75642e2ac22d268278 (diff)
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)
Diffstat (limited to 'website/sandbox/learnpianochords/src/server/Types.hs')
-rw-r--r--website/sandbox/learnpianochords/src/server/Types.hs43
1 files changed, 41 insertions, 2 deletions
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)