blob: 2b52d033bb2f53cf7fca5862e5853b7bc0e3979f (
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
31
32
33
34
35
36
37
|
module Model.User
( getUsers
, getUser
, getJsonUser
, createUser
, deleteUser
) where
import Data.Text (Text)
import Data.Time.Clock (getCurrentTime)
import Control.Monad.IO.Class (liftIO)
import Database.Persist
import Model.Database
import qualified Model.Json.User as Json
getUsers :: Persist [Entity User]
getUsers = selectList [] [Desc UserCreation]
getUser :: Text -> Persist (Maybe (Entity User))
getUser email = selectFirst [UserEmail ==. email] []
getJsonUser :: Entity User -> Json.User
getJsonUser userEntity =
let user = entityVal userEntity
in Json.User (entityKey userEntity) (userName user) (userEmail user)
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]
|