mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
Adds full DNP info to tags (#21)
* Adds full DNP info to tags * Add dnp view * Changed DNP to Dnp
This commit is contained in:
parent
70959e9094
commit
1a6c3731e0
2 changed files with 27 additions and 2 deletions
24
lib/philomena_web/views/api/json/dnp_view.ex
Executable file
24
lib/philomena_web/views/api/json/dnp_view.ex
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule PhilomenaWeb.Api.Json.DnpView do
|
||||||
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
|
def render("index.json", %{dnps: dnp, total: total} = assigns) do
|
||||||
|
%{
|
||||||
|
dnps: render_many(dnp, PhilomenaWeb.Api.Json.DnpView, "dnp.json", assigns),
|
||||||
|
total: total
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def render("show.json", %{dnp: dnp} = assigns) do
|
||||||
|
%{dnp: render_one(dnp, PhilomenaWeb.Api.Json.DnpView, "dnp.json", assigns)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def render("dnp.json", %{dnp: dnp}) do
|
||||||
|
%{
|
||||||
|
id: dnp.id,
|
||||||
|
dnp_type: dnp.dnp_type,
|
||||||
|
conditions: dnp.conditions,
|
||||||
|
reason: if(!dnp.hide_reason, do: dnp.reason),
|
||||||
|
created_at: dnp.created_at
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Api.Json.TagView do
|
||||||
%{tag: render_one(tag, PhilomenaWeb.Api.Json.TagView, "tag.json", assigns)}
|
%{tag: render_one(tag, PhilomenaWeb.Api.Json.TagView, "tag.json", assigns)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("tag.json", %{tag: tag}) do
|
def render("tag.json", %{tag: tag} = assigns) do
|
||||||
%{
|
%{
|
||||||
id: tag.id,
|
id: tag.id,
|
||||||
name: tag.name,
|
name: tag.name,
|
||||||
|
@ -28,7 +28,8 @@ defmodule PhilomenaWeb.Api.Json.TagView do
|
||||||
aliases: Enum.map(tag.aliases, & &1.slug),
|
aliases: Enum.map(tag.aliases, & &1.slug),
|
||||||
implied_tags: Enum.map(tag.implied_tags, & &1.slug),
|
implied_tags: Enum.map(tag.implied_tags, & &1.slug),
|
||||||
implied_by_tags: Enum.map(tag.implied_by_tags, & &1.slug),
|
implied_by_tags: Enum.map(tag.implied_by_tags, & &1.slug),
|
||||||
dnp_entries: Enum.map(tag.dnp_entries, &%{conditions: &1.conditions})
|
dnp_entries:
|
||||||
|
render_many(tag.dnp_entries, PhilomenaWeb.Api.Json.DnpView, "dnp.json", assigns)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue