-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModel.hs
52 lines (44 loc) · 1.57 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
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE FlexibleInstances #-}
module Model where
import ClassyPrelude.Yesod
import Yesod.Markdown (Markdown)
import Database.Persist.Quasi
import Handler.Division
import Helpers
import Model.Permission
import Model.EventLog
import Model.CompetitionState
import Model.RoundState hiding(Finished)
-- 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
, mkDeleteCascade sqlSettings
, mkMigrate "migrateAll"]
$(persistFileWith lowerCaseSettings "config/models")
isFinished :: Entity Competition -> Bool
isFinished = (== Finished) . competitionState . entityVal
displayCompetition :: Competition -> String
displayCompetition competition = name ++ ", " ++ date
where
name = unpack $ competitionName competition
date = showDay $ competitionDate competition
instance ToJSON Score where
toJSON score = object
[ "rid" .= (String $ toPathPiece $ scoreRoundId score)
, "hid" .= (String $ toPathPiece $ scoreHoleId score)
, "score" .= (show $ scoreScore score)
]
instance ToJSON Round where
toJSON round_ = object
[ "uid" .= (String $ toPathPiece $ roundUserId round_)
, "cid" .= (String $ toPathPiece $ roundCompetitionId round_)
, "state" .= (show $ roundState round_)
, "number" .= (show $ roundRoundnumber round_)
, "group" .= (show $ roundGroupnumber round_)
]
instance ToJSON Division where
toJSON division = object
[ "division" .= (show $ division)
]