diff options
author | William Carroll <wpcarro@gmail.com> | 2020-07-24T22·35+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-07-24T22·35+0100 |
commit | 718152ec14242a83fa63c5272c7527dbbd928ee2 (patch) | |
tree | 8a0dfdddfcba4678bb5055ae932e43f3317cc750 /src/Types.hs | |
parent | 1d47e94bbe26479ffaaafecd27cdb83d072bfe01 (diff) |
Return a Session
Define the Session type and return it for the POST /user endpoint
Diffstat (limited to 'src/Types.hs')
-rw-r--r-- | src/Types.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Types.hs b/src/Types.hs index 3a410dc4b525..c2f0ee19b4d7 100644 --- a/src/Types.hs +++ b/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 + ] |