diff --git a/Web/Controller/Projects.hs b/Web/Controller/Projects.hs index 3a742a0..c3200a3 100644 --- a/Web/Controller/Projects.hs +++ b/Web/Controller/Projects.hs @@ -3,22 +3,22 @@ module Web.Controller.Projects where import Web.Controller.Prelude import Web.View.Projects.Index import Web.View.Projects.New +import qualified IHP.QueryBuilder as QueryBuilder instance Controller ProjectsController where action ProjectsAction = do let values :: [(ProjectType, Int)] = [(ProjectTypeOngoing, 3), (ProjectTypeNotStarted, 2)] - valuePairToCondition :: (ProjectType, Int) -> (QueryBuilder "projects" -> QueryBuilder "projects") - valuePairToCondition (projectType, participants) subQuery = - subQuery - |> queryOr - (\qb -> qb |> filterWhere (#projectType, projectType)) - (\qb -> qb |> filterWhere (#participants, participants)) + valuePairToCondition :: (ProjectType, Int) -> QueryBuilder "projects" + valuePairToCondition (projectType, participants) = + query @Project + |> filterWhere (#projectType, projectType) + |> filterWhere (#participants, participants) - conditions = foldl' (\queryBuilder condition -> condition queryBuilder) (query @Project) (map valuePairToCondition values) + theQuery = buildOrQuery (map valuePairToCondition values) - projects <- fetch conditions + projects <- fetch theQuery render IndexView { .. } action NewProjectAction = do @@ -38,3 +38,13 @@ instance Controller ProjectsController where buildProject project = project |> fill @'["projectType", "participants"] + +buildOrQuery :: [QueryBuilder "projects"] -> NoJoinQueryBuilderWrapper "projects" +buildOrQuery (query:rest) = queryUnion query (buildOrQuery rest) +buildOrQuery [] = + let + inner = + query @Project + |> filterWhereSql (#id, "IS NULL") -- Always false condition + in + queryUnion inner inner -- Terrible hack to make the types work out \ No newline at end of file