From 782110a824405143f35ef13ab56e0c45d14b3435 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Wed, 19 Jun 2019 11:11:55 +0200 Subject: [PATCH] feat minor: E.isJust added --- src/Database/Esqueleto/Utils.hs | 7 ++++++- src/Handler/Corrections.hs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Database/Esqueleto/Utils.hs b/src/Database/Esqueleto/Utils.hs index 38105a37a..bd8120ba7 100644 --- a/src/Database/Esqueleto/Utils.hs +++ b/src/Database/Esqueleto/Utils.hs @@ -2,6 +2,7 @@ module Database.Esqueleto.Utils ( true, false + , isJust , isInfixOf, hasInfix , any, all , SqlIn(..) @@ -11,7 +12,7 @@ module Database.Esqueleto.Utils , anyFilter, allFilter ) where -import ClassyPrelude.Yesod hiding (isInfixOf, any, all) +import ClassyPrelude.Yesod hiding (isInfixOf, any, all, isJust) import qualified Data.Set as Set import qualified Data.Foldable as F import qualified Database.Esqueleto as E @@ -34,6 +35,10 @@ true = E.val True false :: E.SqlExpr (E.Value Bool) false = E.val False +-- | Negation of `isNothing` which is missing +isJust :: (E.Esqueleto query expr backend, PersistField typ) => expr (E.Value (Maybe typ)) -> expr (E.Value Bool) +isJust = E.not_ . E.isNothing + -- | Check if the first string is contained in the text derived from the second argument isInfixOf :: (E.Esqueleto query expr backend, E.SqlString s2) => Text -> expr (E.Value s2) -> expr (E.Value Bool) diff --git a/src/Handler/Corrections.hs b/src/Handler/Corrections.hs index dc8cb791e..92a60d00e 100644 --- a/src/Handler/Corrections.hs +++ b/src/Handler/Corrections.hs @@ -337,13 +337,13 @@ makeCorrectionsTable whereClause dbtColonnade dbtFilterUI psValidator dbtProj' d , ( "isassigned" , FilterColumn $ \((_ `E.InnerJoin` _ `E.InnerJoin` submission) `E.LeftOuterJoin` _ :: CorrectionTableExpr) criterion -> case getLast (criterion :: Last Bool) of Nothing -> E.val True :: E.SqlExpr (E.Value Bool) - Just True -> E.not_ . E.isNothing $ submission E.^. SubmissionRatingBy + Just True -> E.isJust $ submission E.^. SubmissionRatingBy Just False-> E.isNothing $ submission E.^. SubmissionRatingBy ) , ( "israted" , FilterColumn $ \((_ `E.InnerJoin` _ `E.InnerJoin` submission) `E.LeftOuterJoin` _ :: CorrectionTableExpr) criterion -> case getLast (criterion :: Last Bool) of Nothing -> E.val True :: E.SqlExpr (E.Value Bool) - Just True -> E.not_ . E.isNothing $ submission E.^. SubmissionRatingTime + Just True -> E.isJust $ submission E.^. SubmissionRatingTime Just False-> E.isNothing $ submission E.^. SubmissionRatingTime ) , ( "corrector-name-email" -- corrector filter does not work for text-filtering