Current section
Files
Jump to
Current section
Files
priv/templates/use_case.gen.phx_resource_json/view.eex
defmodule <%= @context_inflected[:web_module] %>.<%= @schema.alias %>View do
use <%= @context_inflected[:web_module] %>, :view
def render("index.json", %{<%= @schema.plural %>: <%= @schema.plural %>}) do
%{data: render_many(<%= @schema.plural %>, __MODULE__, "<%= @schema.singular %>.json")}
end
def render("show.json", %{<%= @schema.singular %>: <%= @schema.singular %>}) do
%{data: render_one(<%= @schema.singular %>, __MODULE__, "<%= @schema.singular %>.json")}
end
def render("<%= @schema.singular %>.json", %{<%= @schema.singular %>: <%= @schema.singular %>}) do
%{id: <%= @schema.singular %>.id<%= for {k, _} <- @schema.attrs do %>,
<%= k %>: <%= @schema.singular %>.<%= k %><% end %>}
end
end