diff options
Diffstat (limited to 'Model.hs')
-rw-r--r-- | Model.hs | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1,5 +1,6 @@ | |||
1 | {-# LANGUAGE FlexibleInstances #-} | 1 | {-# LANGUAGE FlexibleInstances #-} |
2 | {-# LANGUAGE DeriveFunctor #-} | 2 | {-# LANGUAGE DeriveFunctor #-} |
3 | {-# LANGUAGE PatternGuards #-} | ||
3 | 4 | ||
4 | module Model where | 5 | module Model where |
5 | 6 | ||
@@ -71,10 +72,11 @@ withTypes vals = do | |||
71 | instance Ord Item where | 72 | instance Ord Item where |
72 | x `compare` y = mconcat cmprs | 73 | x `compare` y = mconcat cmprs |
73 | where | 74 | where |
74 | cmprs = [ itemOpened x `compare` itemOpened y | 75 | cmprs = [ comparing itemOpened x y |
75 | , itemExpires x `compare` itemExpires y | 76 | , comparing itemExpires x y |
76 | , itemKind x `compare` itemKind y | 77 | , (comparing not `on` itemRunningLow) x y |
77 | , itemBought x `compare` itemBought y | 78 | , comparing itemKind x y |
79 | , comparing itemBought x y | ||
78 | ] | 80 | ] |
79 | 81 | ||
80 | instance ToJSON Item where | 82 | instance ToJSON Item where |
@@ -83,6 +85,7 @@ instance ToJSON Item where | |||
83 | , "bought" .= itemBought | 85 | , "bought" .= itemBought |
84 | , "expires" .= itemExpires | 86 | , "expires" .= itemExpires |
85 | , "opened" .= itemOpened | 87 | , "opened" .= itemOpened |
88 | , "running-low" .= itemRunningLow | ||
86 | ] | 89 | ] |
87 | 90 | ||
88 | instance FromJSON Item where | 91 | instance FromJSON Item where |
@@ -93,6 +96,7 @@ instance FromJSON Item where | |||
93 | itemBought <- maybe DateUnknown DateKnown <$> obj .:? "bought" | 96 | itemBought <- maybe DateUnknown DateKnown <$> obj .:? "bought" |
94 | itemExpires <- maybe DateNever DateKnown <$> obj .:? "expires" | 97 | itemExpires <- maybe DateNever DateKnown <$> obj .:? "expires" |
95 | itemOpened <- obj .: "opened" | 98 | itemOpened <- obj .: "opened" |
99 | itemRunningLow <- fromMaybe False <$> obj .:? "running-low" | ||
96 | return Item{..} | 100 | return Item{..} |
97 | 101 | ||
98 | instance ToJSON (Entity Item) where | 102 | instance ToJSON (Entity Item) where |