mateamt/src/Types/User.hs

125 lines
2.8 KiB
Haskell
Raw Normal View History

2019-04-17 14:14:44 +00:00
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}
2019-04-17 14:14:44 +00:00
module Types.User where
import GHC.Generics
import Data.Time.Calendar (Day)
import Data.Aeson
import qualified Data.Text as T
-- internal imports
import Classes
2019-04-17 14:14:44 +00:00
data User
= User
{ userId :: Int
, userIdent :: T.Text
, userBalance :: Int
, userTimeStamp :: Day
, userEmail :: Maybe T.Text
, userAvatar :: Maybe Int
-- , userSalt :: AuthSalt
-- , userHash :: Maybe AuthHash
-- , userAlgo :: Maybe Int
2019-04-17 14:14:44 +00:00
}
deriving (Generic, Show)
instance ToDatabase User where
type InTuple User = (Int, T.Text, Int, Day, Maybe T.Text, Maybe Int)
toDatabase (User id_ ident bal ts email ava) =
(id_, ident, bal, ts, email, ava)
instance FromDatabase User where
type OutTuple User = (Int, T.Text, Int, Day, Maybe T.Text, Maybe Int)
fromDatabase (id_, ident, bal, ts, email, ava) =
(User id_ ident bal ts email ava)
2019-05-16 16:37:04 +00:00
2019-09-09 10:54:56 +00:00
data UserSummary = UserSummary
{ userSummaryId :: Int
, userSummaryIdent :: T.Text
, userSummaryAvatar :: Maybe Int
}
deriving (Generic, Show)
instance ToJSON UserSummary where
toEncoding = genericToEncoding defaultOptions
instance FromJSON UserSummary
2019-04-17 14:14:44 +00:00
data UserSubmit = UserSubmit
{ userSubmitIdent :: T.Text
, userSubmitEmail :: Maybe T.Text
, userSubmitPassHash :: T.Text
2019-04-17 14:14:44 +00:00
}
deriving (Generic, Show)
instance ToJSON UserSubmit where
2019-05-16 16:37:04 +00:00
toEncoding = genericToEncoding defaultOptions
2019-04-17 14:14:44 +00:00
instance FromJSON UserSubmit
2019-05-16 16:37:04 +00:00
data UserDetails = UserDetails
2019-09-07 00:48:16 +00:00
{ userDetailsId :: Int
, userDetailsIdent :: T.Text
2019-05-16 16:37:04 +00:00
, userDetailsBalance :: Int
, userDetailsEmail :: Maybe T.Text
, userDetailsAvatar :: Maybe Int
-- , userDetailsSalt :: AuthSalt
-- , userDetailsAlgo :: Maybe AuthAlgorithm
2019-05-16 16:37:04 +00:00
}
deriving (Generic, Show)
instance ToJSON UserDetails where
toEncoding = genericToEncoding defaultOptions
instance FromJSON UserDetails
data UserDetailsSubmit = UserDetailsSubmit
{ userDetailsSubmitIdent :: T.Text
, userDetailsSubmitEmail :: Maybe T.Text
, userDetailsSubmitAvatar :: Maybe Int
-- , userDetailsSubmitHash :: Maybe AuthHash
-- , userDetailsSubmitAlgo :: Maybe AuthAlgorithm
2019-05-16 16:37:04 +00:00
}
deriving (Generic, Show)
instance ToJSON UserDetailsSubmit where
toEncoding = genericToEncoding defaultOptions
instance FromJSON UserDetailsSubmit
2019-08-14 16:03:51 +00:00
2019-10-14 20:50:42 +00:00
newtype UserRecharge = UserRecharge
2019-09-06 19:44:47 +00:00
{ userRechargeAmount :: Int
2019-08-14 16:03:51 +00:00
}
deriving (Generic, Show)
instance ToJSON UserRecharge where
toEncoding = genericToEncoding defaultOptions
instance FromJSON UserRecharge
2019-09-06 19:44:47 +00:00
data UserTransfer = UserTransfer
{ userTransferTarget :: Int
, userTransferAmount :: Int
}
deriving (Generic, Show)
instance ToJSON UserTransfer where
toEncoding = genericToEncoding defaultOptions
instance FromJSON UserTransfer