From 72b9f29c057eb45d022b9bbc1562d7b84ccc165b Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 28 Mar 2017 12:51:25 +0200 Subject: Running low --- Model.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Model.hs') diff --git a/Model.hs b/Model.hs index 8778111..3554049 100644 --- a/Model.hs +++ b/Model.hs @@ -1,5 +1,6 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE PatternGuards #-} module Model where @@ -71,10 +72,11 @@ withTypes vals = do instance Ord Item where x `compare` y = mconcat cmprs where - cmprs = [ itemOpened x `compare` itemOpened y - , itemExpires x `compare` itemExpires y - , itemKind x `compare` itemKind y - , itemBought x `compare` itemBought y + cmprs = [ comparing itemOpened x y + , comparing itemExpires x y + , (comparing not `on` itemRunningLow) x y + , comparing itemKind x y + , comparing itemBought x y ] instance ToJSON Item where @@ -83,6 +85,7 @@ instance ToJSON Item where , "bought" .= itemBought , "expires" .= itemExpires , "opened" .= itemOpened + , "running-low" .= itemRunningLow ] instance FromJSON Item where @@ -93,6 +96,7 @@ instance FromJSON Item where itemBought <- maybe DateUnknown DateKnown <$> obj .:? "bought" itemExpires <- maybe DateNever DateKnown <$> obj .:? "expires" itemOpened <- obj .: "opened" + itemRunningLow <- fromMaybe False <$> obj .:? "running-low" return Item{..} instance ToJSON (Entity Item) where -- cgit v1.2.3