Current section

Files

Jump to
ash_json_api lib ash_json_api controllers generic_action_route.ex
Raw

lib/ash_json_api/controllers/generic_action_route.ex

defmodule AshJsonApi.Controllers.GenericActionRoute do
@moduledoc false
alias AshJsonApi.Controllers.{Helpers, Response}
alias AshJsonApi.Request
def init(options) do
# initialize options
options
end
def call(conn, options) do
resource = options[:resource]
action = options[:action]
domain = options[:domain]
route = options[:route]
all_domains = options[:all_domains]
conn
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
|> Helpers.run_action()
|> Helpers.render_or_render_errors(conn, fn conn, request ->
status =
case route.method do
:post -> 201
_ -> 200
end
Response.render_generic_action_result(
conn,
request,
status,
request.assigns.result,
action.returns
)
end)
end
end