Minor refactor
This commit is contained in:
parent
bc0354da57
commit
ed8beb9e81
@ -92,11 +92,9 @@ getUsersR = do
|
||||
]
|
||||
, dbtFilter = Map.fromList -- OverloadedLists does not work with the templates
|
||||
[ ( "user-search", FilterColumn $ \user criterion ->
|
||||
let eFalse :: E.SqlExpr (E.Value Bool)
|
||||
eFalse = E.val False
|
||||
searchSql needle = E.castString (user E.^. UserDisplayName) `E.ilike` (E.%) E.++. E.val needle E.++. (E.%)
|
||||
in if Set.null criterion then E.val True else -- TODO: why is this condition not needed?
|
||||
Set.foldr (\needle acc -> acc E.||. searchSql needle) eFalse (criterion :: Set.Set Text)
|
||||
-- let searchSql needle = E.castString (user E.^. UserDisplayName) `E.ilike` (E.%) E.++. E.val needle E.++. (E.%) in
|
||||
if Set.null criterion then E.val True else -- TODO: why is this condition not needed?
|
||||
Set.foldr (\needle acc -> acc E.||. (user E.^. UserDisplayName) `eLike` needle) eFalse (criterion :: Set.Set Text)
|
||||
)
|
||||
, ( "matriculation", FilterColumn $ \user criterion -> if
|
||||
| Set.null criterion -> E.val True :: E.SqlExpr (E.Value Bool)
|
||||
@ -105,11 +103,11 @@ getUsersR = do
|
||||
, ( "school", FilterColumn $ \user criterion -> if
|
||||
| Set.null criterion -> E.val True :: E.SqlExpr (E.Value Bool)
|
||||
| otherwise -> let schools = E.valList (Set.toList criterion) in
|
||||
( E.exists $ E.from $ \ulectr -> do
|
||||
E.exists ( E.from $ \ulectr -> do
|
||||
E.where_ $ ulectr E.^. UserLecturerUser E.==. user E.^. UserId
|
||||
E.where_ $ ulectr E.^. UserLecturerSchool `E.in_` schools
|
||||
) E.||.
|
||||
( E.exists $ E.from $ \uadmin -> do
|
||||
E.exists ( E.from $ \uadmin -> do
|
||||
E.where_ $ uadmin E.^. UserAdminUser E.==. user E.^. UserId
|
||||
E.where_ $ uadmin E.^. UserAdminSchool `E.in_` schools
|
||||
)
|
||||
|
||||
@ -12,13 +12,24 @@ import qualified Database.Esqueleto as E
|
||||
|
||||
-- ezero = E.val (0 :: Int64)
|
||||
|
||||
-- | Often needed with this concrete type
|
||||
eTrue :: E.SqlExpr (E.Value Bool)
|
||||
eTrue = E.val True
|
||||
|
||||
-- | Often needed with this concrete type
|
||||
eFalse :: E.SqlExpr (E.Value Bool)
|
||||
eFalse = E.val False
|
||||
|
||||
eLike :: (E.Esqueleto query expr backend, E.SqlString s2, E.SqlString s1) =>
|
||||
expr (E.Value s2) -> s1 -> expr (E.Value Bool)
|
||||
eLike strExpr needle = E.castString strExpr `E.ilike` (E.%) E.++. E.val needle E.++. (E.%)
|
||||
|
||||
emptyOrIn :: PersistField typ =>
|
||||
E.SqlExpr (E.Value typ) -> Set typ -> E.SqlExpr (E.Value Bool)
|
||||
emptyOrIn criterion testSet
|
||||
| Set.null testSet = E.val True
|
||||
| otherwise = criterion `E.in_` E.valList (Set.toList testSet)
|
||||
|
||||
|
||||
entities2map :: PersistEntity record => [Entity record] -> Map (Key record) record
|
||||
entities2map = foldl' (\m entity -> Map.insert (entityKey entity) (entityVal entity) m) Map.empty
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user