-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Query by pairs of values #30
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
|
||
SET statement_timeout = 0; | ||
SET lock_timeout = 0; | ||
SET idle_in_transaction_session_timeout = 0; | ||
SET client_encoding = 'UTF8'; | ||
SET standard_conforming_strings = on; | ||
SELECT pg_catalog.set_config('search_path', '', false); | ||
SET check_function_bodies = false; | ||
SET xmloption = content; | ||
SET client_min_messages = warning; | ||
SET row_security = off; | ||
|
||
|
||
SET SESSION AUTHORIZATION DEFAULT; | ||
|
||
ALTER TABLE public.landing_pages DISABLE TRIGGER ALL; | ||
|
||
|
||
|
||
ALTER TABLE public.landing_pages ENABLE TRIGGER ALL; | ||
|
||
|
||
ALTER TABLE public.paragraph_ctas DISABLE TRIGGER ALL; | ||
|
||
|
||
|
||
ALTER TABLE public.paragraph_ctas ENABLE TRIGGER ALL; | ||
|
||
|
||
ALTER TABLE public.paragraph_quotes DISABLE TRIGGER ALL; | ||
|
||
|
||
|
||
ALTER TABLE public.paragraph_quotes ENABLE TRIGGER ALL; | ||
|
||
|
||
ALTER TABLE public.projects DISABLE TRIGGER ALL; | ||
|
||
INSERT INTO public.projects (id, project_type, participants) VALUES ('e767f087-d1b9-42ea-898e-c2a2bf39999e', 'project_type_ongoing', '2'); | ||
INSERT INTO public.projects (id, project_type, participants) VALUES ('429177d7-f425-4c5e-b379-5e1a0f72bfb5', 'project_type_not_started', '3'); | ||
INSERT INTO public.projects (id, project_type, participants) VALUES ('84825fa3-2cce-4b4a-872b-81fe554e2076', 'project_type_not_started', '2'); | ||
INSERT INTO public.projects (id, project_type, participants) VALUES ('687e32f5-8e8b-4a6d-b4a7-ead9d8a39f91', 'project_type_finished', '2'); | ||
|
||
|
||
ALTER TABLE public.projects ENABLE TRIGGER ALL; | ||
|
||
|
||
ALTER TABLE public.users DISABLE TRIGGER ALL; | ||
|
||
|
||
|
||
ALTER TABLE public.users ENABLE TRIGGER ALL; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Web.Controller.Projects where | ||
|
||
import Web.Controller.Prelude | ||
import Web.View.Projects.Index | ||
import Web.View.Projects.New | ||
|
||
instance Controller ProjectsController where | ||
action ProjectsAction = do | ||
projects <- query @Project |> fetch | ||
|
||
-- Fetch only specific projects by a pair of values. | ||
-- In this case we really fetch all, but show how we pair the values we want to | ||
-- query by. | ||
let pairs = projects | ||
|> fmap (\project -> "(" ++ show project.projectType ++ ", " ++ project.participants ++ ")") | ||
|
||
projectsQuery :: [Project] <- sqlQuery "SELECT * FROM projects WHERE (project_type, participants) IN (VALUES ?)" (Only (In pairs)) | ||
|
||
render IndexView { .. } | ||
|
||
action NewProjectAction = do | ||
let project = newRecord | ||
render NewView { .. } | ||
|
||
action CreateProjectAction = do | ||
let project = newRecord @Project | ||
project | ||
|> buildProject | ||
|> ifValid \case | ||
Left project -> render NewView { .. } | ||
Right project -> do | ||
project <- project |> createRecord | ||
setSuccessMessage "Project created" | ||
redirectTo ProjectsAction | ||
|
||
buildProject project = project | ||
|> fill @'["projectType", "participants"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ instance AutoRoute SessionsController | |
|
||
instance AutoRoute UsersController | ||
|
||
|
||
instance AutoRoute ProjectsController | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Web.View.Projects.Index where | ||
import Web.View.Prelude | ||
|
||
data IndexView = IndexView { projects :: [Project] } | ||
|
||
instance View IndexView where | ||
html IndexView { .. } = [hsx| | ||
{breadcrumb} | ||
|
||
<h1>Index<a href={pathTo NewProjectAction} class="btn btn-primary ms-4">+ New</a></h1> | ||
<div class="table-responsive"> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Project</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody>{forEach projects renderProject}</tbody> | ||
</table> | ||
|
||
</div> | ||
|] | ||
where | ||
breadcrumb = renderBreadcrumb | ||
[ breadcrumbLink "Projects" ProjectsAction | ||
] | ||
|
||
renderProject :: Project -> Html | ||
renderProject project = [hsx| | ||
<tr> | ||
<td>{project.projectType} {project.participants}</td> | ||
</tr> | ||
|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Web.View.Projects.New where | ||
import Web.View.Prelude | ||
|
||
data NewView = NewView { project :: Project } | ||
|
||
instance View NewView where | ||
html NewView { .. } = [hsx| | ||
{breadcrumb} | ||
<h1>New Project</h1> | ||
{renderForm project} | ||
|] | ||
where | ||
breadcrumb = renderBreadcrumb | ||
[ breadcrumbLink "Projects" ProjectsAction | ||
, breadcrumbText "New Project" | ||
] | ||
|
||
renderForm :: Project -> Html | ||
renderForm project = formFor project [hsx| | ||
{(selectField #projectType allProjectTypes)} | ||
{(numberField #participants)} | ||
{submitButton} | ||
|] | ||
where allProjectTypes = allEnumValues @ProjectType |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the query. It compiles, but isn't right:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to implement ToField:
But this now has this error