summaryrefslogtreecommitdiff
path: root/Handler/List.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-16 13:18:34 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-16 13:18:34 +0100
commit57d594818c14652681dce54d324b6b76941b2f4e (patch)
treef3e1e02e2fa41ff0d87eace034d6c883668841c5 /Handler/List.hs
parent3d828feba67f21ae62d1e6eb598a22ffaebf1174 (diff)
parent3bfe0bdcb79b398a387e202c5150b5e6fd230d3a (diff)
downloadbar-57d594818c14652681dce54d324b6b76941b2f4e.tar
bar-57d594818c14652681dce54d324b6b76941b2f4e.tar.gz
bar-57d594818c14652681dce54d324b6b76941b2f4e.tar.bz2
bar-57d594818c14652681dce54d324b6b76941b2f4e.tar.xz
bar-57d594818c14652681dce54d324b6b76941b2f4e.zip
Merge branch 'feat/openYes'
Diffstat (limited to 'Handler/List.hs')
-rw-r--r--Handler/List.hs20
1 files changed, 17 insertions, 3 deletions
diff --git a/Handler/List.hs b/Handler/List.hs
index 21b735b..7ab4ebe 100644
--- a/Handler/List.hs
+++ b/Handler/List.hs
@@ -19,9 +19,23 @@ import Database.Persist.Sql (Single(..), rawSql)
19import Thermoprint.Client 19import Thermoprint.Client
20 20
21list :: Handler (Set (WithType Text)) 21list :: Handler (Set (WithType Text))
22list = do 22list = runDB $ do
23 (map (uncurry WithType . bimap unSingle unSingle) -> kinds) <- runDB $ rawSql "select reference.kind, kind.type from reference,kind where (not exists (select * from item where COALESCE(item.expires >= CURRENT_DATE, TRUE) and (item.norm_kind = reference.norm_kind))) and (reference.norm_kind = kind.norm_kind)" [] 23 today <- liftIO $ utctDay <$> getCurrentTime
24 return $ Set.fromList kinds 24
25 items <- map entityVal <$> selectList [] []
26 references <- Set.fromList <$> (withTypes . fmap entityVal =<< selectList [] [])
27
28 let
29 references' = Set.filter (isNothing . flip find items . matches) references
30 matches (Reference{..} `WithType` _) Item{..}
31 | today `isBefore` itemExpires = itemNormKind == referenceNormKind
32 | otherwise = False
33
34 isBefore _ DateNever = True
35 isBefore _ DateUnknown = False
36 isBefore d1 (DateKnown d2) = d1 < d2
37
38 return $ Set.map (fmap referenceKind) references'
25 39
26mkPrintout :: Set (WithType Text) -> Printout 40mkPrintout :: Set (WithType Text) -> Printout
27mkPrintout list = Printout ps 41mkPrintout list = Printout ps