Packages

A way to increase Elixir projects readability and maintenance based on Use Cases and Interactors.

Current section

Files

Jump to
use_case priv templates use_case.gen.phx_resource_json view.eex
Raw

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