diff options
author | Joris Guyonvarch | 2015-07-06 00:16:45 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-07-06 00:16:45 +0200 |
commit | 4ce9751c9e645916fdde71874c2cdadd252f32a0 (patch) | |
tree | 1014c58787231cbdc3ae2799f32127b40ab393ab /src/server/Model/User.hs |
Setting up Scotty, Persistent, Clay, Blaze, Esqueleto, Elm
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] |