From 1a6c3731e02484ce1cdb8de0a8d744b956818c9f Mon Sep 17 00:00:00 2001 From: SomewhatDamaged Date: Thu, 24 Sep 2020 23:46:05 +1000 Subject: [PATCH] Adds full DNP info to tags (#21) * Adds full DNP info to tags * Add dnp view * Changed DNP to Dnp --- lib/philomena_web/views/api/json/dnp_view.ex | 24 ++++++++++++++++++++ lib/philomena_web/views/api/json/tag_view.ex | 5 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 lib/philomena_web/views/api/json/dnp_view.ex diff --git a/lib/philomena_web/views/api/json/dnp_view.ex b/lib/philomena_web/views/api/json/dnp_view.ex new file mode 100755 index 00000000..ad07db2f --- /dev/null +++ b/lib/philomena_web/views/api/json/dnp_view.ex @@ -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 diff --git a/lib/philomena_web/views/api/json/tag_view.ex b/lib/philomena_web/views/api/json/tag_view.ex index 0ef5f813..8aaa6248 100644 --- a/lib/philomena_web/views/api/json/tag_view.ex +++ b/lib/philomena_web/views/api/json/tag_view.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Api.Json.TagView do %{tag: render_one(tag, PhilomenaWeb.Api.Json.TagView, "tag.json", assigns)} end - def render("tag.json", %{tag: tag}) do + def render("tag.json", %{tag: tag} = assigns) do %{ id: tag.id, name: tag.name, @@ -28,7 +28,8 @@ defmodule PhilomenaWeb.Api.Json.TagView do aliases: Enum.map(tag.aliases, & &1.slug), implied_tags: Enum.map(tag.implied_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