Skip to content

Commit c65b5d1

Browse files
authored
Merge pull request #1271 from code-corps/make-acceptance-filter-optional
Make project acceptance filter optional
2 parents 350065c + 961c909 commit c65b5d1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/code_corps/project/query.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ defmodule CodeCorps.Project.Query do
33
Contains queries for retrieving projects
44
"""
55
alias CodeCorps.{
6+
Helpers.Query,
67
Project,
78
SluggedRoute,
89
Repo
910
}
1011

11-
import Ecto.Query
12-
1312
@doc ~S"""
1413
Returns a list of `Project` records based on the provided filter.
1514
1615
If the filter contains a `slug` key, returns all projects for the specified
1716
`Organization.`
1817
19-
If the filter does not contain a `slug` key, returns all `approved` projects.
18+
If the filter does not contain a `slug` key, filters by optional params.
2019
"""
2120
@spec list(map) :: list(Project.t)
2221
def list(%{"slug" => slug}) do
@@ -26,10 +25,10 @@ defmodule CodeCorps.Project.Query do
2625
|> Map.get(:organization)
2726
|> Map.get(:projects)
2827
end
29-
def list(%{}) do
28+
def list(%{} = params) do
3029
Project
31-
|> where(approved: true)
32-
|> Repo.all
30+
|> Query.optional_filters(params, ~w(approved)a)
31+
|> Repo.all()
3332
end
3433

3534
@doc ~S"""

test/lib/code_corps_web/controllers/project_controller_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ defmodule CodeCorpsWeb.ProjectControllerTest do
1111
@invalid_attrs %{title: ""}
1212

1313
describe "index" do
14-
test "lists all approved entries on index", %{conn: conn} do
14+
test "filters on index", %{conn: conn} do
1515
[project_1, project_2] = insert_pair(:project, approved: true)
1616
project_3 = insert(:project, approved: false)
1717

18+
path = "/projects?approved=true"
19+
1820
returned_ids =
1921
conn
20-
|> request_index
22+
|> get(path)
2123
|> json_response(200)
2224
|> ids_from_response
2325

0 commit comments

Comments
 (0)