Return a Session
Define the Session type and return it for the POST /user endpoint
This commit is contained in:
parent
1d47e94bbe
commit
718152ec14
3 changed files with 49 additions and 11 deletions
33
src/Types.hs
33
src/Types.hs
|
|
@ -33,3 +33,36 @@ instance ToJSON User where
|
|||
object [ "name" .= name
|
||||
, "age" .= age
|
||||
]
|
||||
|
||||
newtype Username = Username Text
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance ToJSON Username where
|
||||
toJSON (Username x) = toJSON x
|
||||
|
||||
newtype Password = Password Text
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance ToJSON Password where
|
||||
toJSON (Password x) = toJSON x
|
||||
|
||||
data Role = RegularUser | Manager | Admin
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance ToJSON Role where
|
||||
toJSON RegularUser = "user"
|
||||
toJSON Manager = "manager"
|
||||
toJSON Admin = "admin"
|
||||
|
||||
data Session = Session
|
||||
{ username :: Username
|
||||
, password :: Password
|
||||
, role :: Role
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance ToJSON Session where
|
||||
toJSON (Session username password role) =
|
||||
object [ "username" .= username
|
||||
, "password" .= password
|
||||
, "role" .= role
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue