diff options
Diffstat (limited to 'Model.hs')
-rw-r--r-- | Model.hs | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -45,14 +45,18 @@ withType :: ( BaseBackend backend ~ SqlBackend | |||
45 | withType val = (val `WithType`) . kindType <$> getType val | 45 | withType val = (val `WithType`) . kindType <$> getType val |
46 | 46 | ||
47 | instance Ord Item where | 47 | instance Ord Item where |
48 | x `compare` y = mconcat | 48 | x `compare` y = mconcat cmprs |
49 | [ (isNothing $ itemOpened x) `compare` (isNothing $ itemOpened y) | 49 | where |
50 | , itemOpened x `compare` itemOpened y | 50 | cmprs = [ itemOpened x `compareM` itemOpened y |
51 | , (isNothing $ itemExpires x) `compare` (isNothing $ itemExpires y) | 51 | , itemExpires x `compareM` itemExpires y |
52 | , itemExpires x `compare` itemExpires x | 52 | , itemKind x `compare` itemKind y |
53 | , itemKind x `compare` itemKind x | 53 | , itemBought x `compare` itemBought y |
54 | , itemBought x `compare` itemBought x | 54 | ] |
55 | ] | 55 | |
56 | compareM (Just _) Nothing = LT | ||
57 | compareM Nothing (Just _) = GT | ||
58 | compareM (Just a) (Just b) = compare a b | ||
59 | compareM _ _ = EQ | ||
56 | 60 | ||
57 | instance ToJSON Item where | 61 | instance ToJSON Item where |
58 | toJSON Item{..} = object $ | 62 | toJSON Item{..} = object $ |
@@ -124,7 +128,7 @@ toUpdate (ItemDiffs ds) = mconcat $ do | |||
124 | DiffOpened d -> (, []) [ ItemOpened =. d ] | 128 | DiffOpened d -> (, []) [ ItemOpened =. d ] |
125 | 129 | ||
126 | data WithType a = WithType { typedVal :: a, valType :: Text } | 130 | data WithType a = WithType { typedVal :: a, valType :: Text } |
127 | deriving (Eq, Ord) | 131 | deriving (Eq, Ord, Show) |
128 | 132 | ||
129 | typeToJSON :: ToJSON a | 133 | typeToJSON :: ToJSON a |
130 | => Text -- ^ Key for value, if needed | 134 | => Text -- ^ Key for value, if needed |