summaryrefslogtreecommitdiff
path: root/Model.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-28 12:51:25 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-28 12:51:25 +0200
commit72b9f29c057eb45d022b9bbc1562d7b84ccc165b (patch)
tree978b71348b0dce981adf55c72ced58e8a750a17b /Model.hs
parent08759871bcc3dc3b461650232747e58653535cdb (diff)
downloadbar-72b9f29c057eb45d022b9bbc1562d7b84ccc165b.tar
bar-72b9f29c057eb45d022b9bbc1562d7b84ccc165b.tar.gz
bar-72b9f29c057eb45d022b9bbc1562d7b84ccc165b.tar.bz2
bar-72b9f29c057eb45d022b9bbc1562d7b84ccc165b.tar.xz
bar-72b9f29c057eb45d022b9bbc1562d7b84ccc165b.zip
Running low
Diffstat (limited to 'Model.hs')
-rw-r--r--Model.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/Model.hs b/Model.hs
index 8778111..3554049 100644
--- a/Model.hs
+++ b/Model.hs
@@ -1,5 +1,6 @@
1{-# LANGUAGE FlexibleInstances #-} 1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE DeriveFunctor #-} 2{-# LANGUAGE DeriveFunctor #-}
3{-# LANGUAGE PatternGuards #-}
3 4
4module Model where 5module Model where
5 6
@@ -71,10 +72,11 @@ withTypes vals = do
71instance Ord Item where 72instance 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
80instance ToJSON Item where 82instance 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
88instance FromJSON Item where 91instance 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
98instance ToJSON (Entity Item) where 102instance ToJSON (Entity Item) where