about summary refs log tree commit diff
path: root/website/sandbox/learnpianochords/src/server/Types.hs
blob: 2303a752e4ad6c045ebdeeb070be60fa53d395b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
--------------------------------------------------------------------------------
module Types where
--------------------------------------------------------------------------------
import RIO
import Data.Aeson
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.
data Context = Context
  { contextGoogleClientID :: !String
  , contextServerPort :: !Int
  , contextClientPort :: !Int
  }

-- | 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
  } deriving (Eq, Show)

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)