Skip to content

Commit 6bad267

Browse files
authored
Merge pull request #746 from code-corps/add-approved-to-projects-index
Add approved to projects index
2 parents 7c89c33 + d8c6c86 commit 6bad267

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

lib/code_corps/helpers/query.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ defmodule CodeCorps.Helpers.Query do
77
query |> where([object], object.id in ^ids)
88
end
99

10+
# project queries
11+
12+
def approved_filter(query, approved) do
13+
query |> where([object], object.approved == ^approved)
14+
end
15+
16+
# end project queries
17+
1018
# skill queries
1119

1220
def limit_filter(query, %{"limit" => count}) do

test/controllers/project_controller_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ defmodule CodeCorps.ProjectControllerTest do
55
@invalid_attrs %{title: ""}
66

77
describe "index" do
8-
test "lists all entries on index", %{conn: conn} do
9-
[project_1, project_2] = insert_pair(:project)
8+
test "lists all approved entries on index", %{conn: conn} do
9+
[project_1, project_2] = insert_pair(:project, approved: true)
10+
insert(:project, approved: false)
1011

1112
conn
1213
|> request_index

test/support/factories.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ defmodule CodeCorps.Factories do
7575

7676
def project_factory do
7777
%CodeCorps.Project{
78-
title: sequence(:title, &"Project #{&1}"),
78+
approved: true,
7979
slug: sequence(:slug, &"project-#{&1}"),
80+
title: sequence(:title, &"Project #{&1}"),
81+
website: sequence(:website, &"http://test-#{&1}.com"),
82+
8083
organization: build(:organization),
81-
owner: build(:user),
82-
website: sequence(:website, &"http://test-#{&1}.com")
84+
owner: build(:user)
8385
}
8486
end
8587

test/views/project_view_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule CodeCorps.ProjectViewTest do
44
test "renders all attributes and relationships properly" do
55
user = insert(:user)
66
organization = insert(:organization)
7-
project = insert(:project, organization: organization, owner: user, total_monthly_donated: 5000, default_color: "blue")
7+
project = insert(:project, organization: organization, owner: user, total_monthly_donated: 5000, default_color: "blue", approved: true)
88

99
donation_goal = insert(:donation_goal, project: project)
1010
project_category = insert(:project_category, project: project)
@@ -21,6 +21,7 @@ defmodule CodeCorps.ProjectViewTest do
2121
expected_json = %{
2222
"data" => %{
2323
"attributes" => %{
24+
"approved" => true,
2425
"can-activate-donations" => false,
2526
"cloudinary-public-id" => nil,
2627
"description" => project.description,

web/controllers/project_controller.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule CodeCorps.ProjectController do
22
use CodeCorps.Web, :controller
33
use JaResource
44

5-
import CodeCorps.Helpers.Query, only: [slug_finder: 2]
5+
import CodeCorps.Helpers.Query, only: [approved_filter: 2, slug_finder: 2]
66

77
alias CodeCorps.Project
88

@@ -21,7 +21,10 @@ defmodule CodeCorps.ProjectController do
2121
Project
2222
|> Repo.all(organization_id: slugged_route.organization_id)
2323
end
24-
def handle_index(_conn, _params), do: Project
24+
def handle_index(_conn, _params) do
25+
Project
26+
|> approved_filter(true)
27+
end
2528

2629
def handle_create(_conn, attributes) do
2730
%Project{} |> Project.create_changeset(attributes)

web/views/project_view.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ defmodule CodeCorps.ProjectView do
1212
use JaSerializer.PhoenixView
1313

1414
attributes [
15-
:slug, :title, :can_activate_donations, :cloudinary_public_id,
15+
:approved, :can_activate_donations, :cloudinary_public_id,
1616
:description, :donations_active, :icon_thumb_url,
17-
:icon_large_url, :long_description_body, :long_description_markdown,
18-
:inserted_at, :should_link_externally, :total_monthly_donated, :updated_at,
19-
:website
17+
:icon_large_url, :inserted_at, :long_description_body,
18+
:long_description_markdown, :should_link_externally, :slug, :title,
19+
:total_monthly_donated, :updated_at, :website
2020
]
2121

2222
has_one :organization, serializer: CodeCorps.OrganizationView

0 commit comments

Comments
 (0)