diff options
Diffstat (limited to 'src/server/Model/User.hs')
-rw-r--r-- | src/server/Model/User.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server/Model/User.hs b/src/server/Model/User.hs new file mode 100644 index 0000000..ddca0fb --- /dev/null +++ b/src/server/Model/User.hs @@ -0,0 +1,30 @@ +module Model.User + ( getUsers + , getUser + , insertUser + , deleteUser + ) where + +import Data.Text (Text) +import Data.Time.Clock (getCurrentTime) + +import Control.Monad.IO.Class (liftIO) + +import Database.Persist + +import Model.Database + +getUsers :: Persist [User] +getUsers = map entityVal <$> selectList [] [Desc UserCreation] + +getUser :: Text -> Persist (Maybe (Entity User)) +getUser email = selectFirst [UserEmail ==. email] [] + +insertUser :: Text -> Text -> Persist UserId +insertUser email name = do + now <- liftIO getCurrentTime + insert $ User now email name + +deleteUser :: Text -> Persist () +deleteUser email = + deleteWhere [UserEmail ==. email] |