File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
test/lib/code_corps_web/controllers Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff 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"""
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments