Current section

Files

Jump to
ash_json_api lib ash_json_api controllers patch.ex
Raw

lib/ash_json_api/controllers/patch.ex

# SPDX-FileCopyrightText: 2019 ash_json_api contributors <https://github.com/ash-project/ash_json_api/graphs/contributors>
#
# SPDX-License-Identifier: MIT
defmodule AshJsonApi.Controllers.Patch 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.update_record()
|> Helpers.fetch_includes()
|> Helpers.fetch_metadata()
|> Helpers.render_or_render_errors(conn, fn conn, request ->
Response.render_one(conn, request, 200, request.assigns.result, request.assigns.includes)
end)
end
end