-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoles.hs
34 lines (29 loc) · 934 Bytes
/
Roles.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
module Roles where
import Prelude ( Maybe (..)
, Read
, Show
, Enum
, Eq
, Bounded
, show
, (.)
)
import Database.Persist.TH
import Yesod.Core.Dispatch (PathPiece (..))
data Role = Consumer | InnerCircle | Admin
deriving (Read, Show, Eq, Enum, Bounded)
data ListRole = Receiver | Sender
deriving (Read, Show, Eq, Enum, Bounded)
derivePersistField "Role"
derivePersistField "ListRole"
instance PathPiece Role where
toPathPiece = toPathPiece . show
fromPathPiece "Consumer" = Just Consumer
fromPathPiece "InnerCircle" = Just InnerCircle
fromPathPiece "Admin" = Just Admin
fromPathPiece _ = Nothing
instance PathPiece ListRole where
toPathPiece = toPathPiece . show
fromPathPiece "Receiver" = Just Receiver
fromPathPiece "Sender" = Just Sender
fromPathPiece _ = Nothing