defmodule <%= @context_inflected[:web_module] %>.<%= @schema.alias %>Controller do use <%= @context_inflected[:web_module] %>, :controller alias <%= @context_inflected[:base] %>.<%= @context_inflected[:scoped] %> action_fallback <%= @context_inflected[:web_module] %>.FallbackController def index(conn, _params) do render(conn, "index.json", <%= @schema.plural %>: <%= @context_inflected[:alias] %>.list()) end def create(conn, %{<%= inspect @schema.singular %> => <%= @schema.singular %>_params}) do with {:ok, <%= @schema.singular %>} <- <%= @context_inflected[:alias] %>.create(<%= @schema.singular %>_params) do conn |> put_status(:created) |> put_resp_header("location", Routes.<%= @schema.route_helper %>_path(conn, :show, <%= @schema.singular %>)) |> render("show.json", <%= @schema.singular %>: <%= @schema.singular %>) end end def show(conn, %{"id" => id}) do render(conn, "show.json", <%= @schema.singular %>: <%= @context_inflected[:alias] %>.get!(id)) end def update(conn, %{"id" => id, <%= inspect @schema.singular %> => <%= @schema.singular %>_params}) do <%= @schema.singular %> = <%= @context_inflected[:alias] %>.get!(id) with {:ok, _} <- <%= @context_inflected[:alias] %>.update(<%= @schema.singular %>, <%= @schema.singular %>_params) do render(conn, "show.json", <%= @schema.singular %>: <%= @schema.singular %>) end end def delete(conn, %{"id" => id}) do with {:ok, _} <- <%= @context_inflected[:alias] %>.delete(<%= @context_inflected[:alias] %>.get!(id)) do send_resp(conn, :no_content, "") end end end