2020-07-30 16:05:09 +00:00
|
|
|
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>View do
|
|
|
|
use <%= inspect context.module %>, :view
|
|
|
|
alias <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>View
|
2020-07-29 17:07:36 +00:00
|
|
|
|
|
|
|
def render("index.json", %{<%= schema.plural %>: <%= schema.plural %>}) do
|
|
|
|
%{data: render_many(<%= schema.plural %>, <%= inspect schema.alias %>View, "<%= schema.singular %>.json")}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("show.json", %{<%= schema.singular %>: <%= schema.singular %>}) do
|
|
|
|
%{data: render_one(<%= schema.singular %>, <%= inspect schema.alias %>View, "<%= 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
|