Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ config :sentry,
included_environments: ~w(prod staging)a,
use_error_logger: true

config :jsonapi,
underscore_to_dash: true

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
Expand Down
2 changes: 1 addition & 1 deletion lib/code_corps_web/controllers/category_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule CodeCorpsWeb.CategoryController do
@spec show(Conn.t, map) :: Conn.t
def show(%Conn{} = conn, %{"id" => id}) do
with %Category{} = category <- Category |> Repo.get(id) |> preload() do
conn |> render("show.json-api", data: category)
conn |> render(CodeCorpsWeb.CategoryView, "show.json-api", %{ data: category, conn: conn, params: id })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can just call the show action provided by the jsonapi lib instead of calling render....?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems plausible. Have you tried this?

end
end

Expand Down
9 changes: 6 additions & 3 deletions lib/code_corps_web/views/category_view.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
defmodule CodeCorpsWeb.CategoryView do
@moduledoc false
use CodeCorpsWeb, :view
use JaSerializer.PhoenixView
use JSONAPI.View, type: "category"

attributes [:name, :slug, :description]
def render("show.json-api", %{ data: category, conn: conn, params: params }) do
__MODULE__.show(category, conn, params)
end

has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, identifiers: :always
def fields, do: [:name, :slug, :description]
def relationships, do: [project_categories: CodeCorpsWeb.ProjectCategoryView]
end
7 changes: 4 additions & 3 deletions lib/code_corps_web/views/project_category_view.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
defmodule CodeCorpsWeb.ProjectCategoryView do
@moduledoc false
use CodeCorpsWeb, :view
use JaSerializer.PhoenixView
use JSONAPI.View, type: "project-category"

has_one :project, type: "project", field: :project_id
has_one :category, type: "category", field: :category_id
def fields, do: []
def relationships, do: [project: CodeCorpsWeb.ProjectView,
category: CodeCorpsWeb.CategoryView]
end
1 change: 1 addition & 0 deletions lib/code_corps_web/views/project_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule CodeCorpsWeb.ProjectView do

use CodeCorpsWeb, :view
use JaSerializer.PhoenixView
use JSONAPI.View, type: "project"

attributes [
:approved, :can_activate_donations, :cloudinary_public_id,
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ defmodule CodeCorps.Mixfile do
{:inflex, "~> 1.8.1"},
{:ja_serializer, "~> 0.12"}, # JSON API
{:joken, "~> 1.5"}, # JWT encoding
{:jsonapi, git: "https://github.com/jeregrine/jsonapi.git"},
{:money, "~> 1.2.1"},
{:poison, "~> 3.0", override: true},
{:scout_apm, "~> 0.0"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ja_serializer": {:hex, :ja_serializer, "0.12.0", "ba4ec5fc7afa6daba815b5cb2b9bd0de410554ac4f0ed54e954d39decb353ca4", [:mix], [{:inflex, "~> 1.4", [hex: :inflex, optional: false]}, {:plug, "> 1.0.0", [hex: :plug, optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, optional: false]}, {:scrivener, "~> 1.2 or ~> 2.0", [hex: :scrivener, optional: true]}]},
"joken": {:hex, :joken, "1.5.0", "42a0953e80bd933fc98a0874e156771f78bf0e92abe6c3a9c22feb6da28efb0b", [:mix], [{:jose, "~> 1.8", [hex: :jose, optional: false]}, {:plug, "~> 1.0", [hex: :plug, optional: true]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: true]}]},
"jose": {:hex, :jose, "1.8.4", "7946d1e5c03a76ac9ef42a6e6a20001d35987afd68c2107bcd8f01a84e75aa73", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, optional: false]}]},
"jsonapi": {:git, "https://github.com/jeregrine/jsonapi.git", "1cb176095773c8d481c38ec0f6b22c36fbff618a", []},
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], []},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], []},
Expand Down
Loading