aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model/User.hs
blob: 339aff65d0501b1bf2b54df96ce2d084aff04587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Model.User
  ( getUsers
  , getUser
  , createUser
  , 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] []

createUser :: Text -> Text -> Persist UserId
createUser email name = do
  now <- liftIO getCurrentTime
  insert $ User now email name

deleteUser :: Text -> Persist ()
deleteUser email =
  deleteWhere [UserEmail ==. email]