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:
SomewhatDamaged 2020-09-24 23:46:05 +10:00 committed by GitHub
parent 70959e9094
commit 1a6c3731e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View 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

View file

@ -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