From 06c4e0c2c390ac4406a530f3546b60c36ef45847 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel <> Date: Wed, 5 Aug 2020 11:39:24 +0200 Subject: [PATCH] refactor(course-visibility): use E.maybe --- src/Handler/Allocation/List.hs | 7 ++++--- src/Utils/Course.hs | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Handler/Allocation/List.hs b/src/Handler/Allocation/List.hs index de8753751..497879edd 100644 --- a/src/Handler/Allocation/List.hs +++ b/src/Handler/Allocation/List.hs @@ -41,9 +41,10 @@ countCourses muid ata now addWhere allocation = E.subSelectCount . E.from $ \all ) E.||. (E.isJust (allocation E.^. AllocationRegisterFrom) E.&&. allocation E.^. AllocationRegisterFrom E.<=. E.val (Just now) - E.&&. (E.isNothing (allocation E.^. AllocationRegisterTo) - E.||. E.val (Just now) E.<=. allocation E.^. AllocationRegisterTo - ) + E.&&. E.maybe + (E.val True) + (\registerTo -> E.val now E.<=. registerTo) + (allocation E.^. AllocationRegisterTo) ) ) ) diff --git a/src/Utils/Course.hs b/src/Utils/Course.hs index f5ee489b3..18c3db230 100644 --- a/src/Utils/Course.hs +++ b/src/Utils/Course.hs @@ -80,10 +80,10 @@ courseIsVisible :: UTCTime -> E.SqlExpr (Entity Course) -> E.SqlExpr (E.Value Bo courseIsVisible now course = E.isJust (course E.^. CourseVisibleFrom) E.&&. course E.^. CourseVisibleFrom E.<=. E.val (Just now) - E.&&. ( - E.isNothing (course E.^. CourseVisibleTo) - E.||. E.val (Just now) E.<=. course E.^. CourseVisibleTo - ) + E.&&. E.maybe + (E.val True) + (\visibleTo -> E.val now E.<=. visibleTo) + (course E.^. CourseVisibleTo) courseIsVisible' :: UTCTime -> Course -> Bool courseIsVisible' now Course{..} = NTop courseVisibleFrom <= now' && now' <= NTop courseVisibleTo