View Source ExTeal.Resource.Delete behaviour (ExTeal v0.27.0)

Defines a behaviour for deleting a resource and the function to execute it.

It relies on (and uses):

  • ExTeal.Repo
  • ExTeal.Record

When used ExTeal.Resource.Delete defines the delete/2 action suitable for handling teal delete requests.

To customize the behaviour of the update action the following callbacks can be implemented:

  • handle_delete/2
  • ExTeal.Record.record/2
  • ExTeal.Repo.repo/0

Summary

Callbacks

Returns an unpersisted changeset or persisted model representing the newly updated model.

Functions

Execute the delete action on a given module implementing Delete behaviour and conn.

Callbacks

@callback handle_delete(Ecto.Query.t(), Plug.Conn.t()) :: {integer(), nil | [term()]}

Returns an unpersisted changeset or persisted model representing the newly updated model.

Receives the conn and the record as found by record/2.

Default implementation returns the results of calling Repo.delete(record).

Example custom implementation:

def handle_delete(conn, record) do
  case conn.assigns[:user] do
    %{is_admin: true} -> super(conn, record)
    _                 -> send_resp(conn, 401, "nope")
  end
end

Functions

Execute the delete action on a given module implementing Delete behaviour and conn.