-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModel.hs
41 lines (34 loc) · 1.31 KB
/
Model.hs
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
38
39
40
41
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE StandaloneDeriving #-}
module Model where
import Prelude hiding (concat)
import Yesod
import Data.Text (Text, concat, pack)
import Database.Persist.Quasi
import Database.Persist.Sql
import Data.Typeable ()
import Data.Time
import Data.Data
import Roles
import Languages
-- You can define all of your database entities in the entities file.
-- You can find more information on persistent and how to declare entities
-- at:
-- http://www.yesodweb.com/book/persistent/
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
$(persistFileWith lowerCaseSettings "config/models")
data Message = Message { messageSubject :: Text
, messageBody :: Textarea
}
anchor :: ToBackendKey SqlBackend ent => Key ent -> Text
anchor = pack . show . fromSqlKey
routeAnchor :: (Yesod master, ToBackendKey SqlBackend ent) => Route master -> Key ent -> HandlerFor master Text
routeAnchor route key = do
renderUrl <- getUrlRender
return $ concat [ renderUrl route
, "#"
, anchor key
]
redirectAnchor :: (Yesod master, ToBackendKey SqlBackend ent)
=> Route master -> Key ent -> HandlerFor master Text
redirectAnchor route key = routeAnchor route key >>= redirect