35 lines
916 B
Haskell
35 lines
916 B
Haskell
{-# LANGUAGE OverloadedStrings, RecordWildCards, TypeFamilies, MultiParamTypeClasses, FlexibleInstances, AllowAmbiguousTypes #-}
|
|
|
|
module User
|
|
( UserData(..)
|
|
, User (..)
|
|
) where
|
|
|
|
import Data.Aeson
|
|
import Data.Map.Strict
|
|
import Data.Text hiding (singleton)
|
|
|
|
import GHC.Generics
|
|
|
|
|
|
class (Show u, ToJSON a, Monoid a) => UserData u a where -- TODO Show maybe not necessary, but currently needed for TypeApplications
|
|
data Scope u
|
|
readScope :: String -> Scope u
|
|
showScope :: Scope u -> String
|
|
userScope :: u -> Scope u -> a
|
|
|
|
|
|
data User = User
|
|
{ name :: Text
|
|
, email :: Text
|
|
, password :: Text
|
|
, uID :: Text
|
|
} deriving (Eq, Show)
|
|
|
|
|
|
instance UserData User (Map Text Text) where
|
|
data Scope User = ID | Profile deriving (Show, Read, Eq)
|
|
readScope = read
|
|
showScope = show
|
|
userScope User{..} ID = singleton "id" uID
|
|
userScope User{..} Profile = fromList [("name", name), ("email", email)] |