ja_resource v0.2.0 JaResource.Delete behaviour
Defines a behaviour for deleting a resource and the function to execute it.
It relies on (and uses):
- JaResource.Repo
- JaResource.Record
When used JaResource.Delete defines the delete/2
action suitable for
handling json-api requests.
To customize the behaviour of the update action the following callbacks can be implemented:
- handle_delete/2
- JaResource.Record.record/2
- JaResource.Repo.repo/0
Summary
Functions
Execute the delete action on a given module implementing Delete behaviour and conn
Callbacks
Returns an unpersisted changeset or persisted model representing the newly updated model
Functions
Callbacks
Specs
handle_delete(Plug.Conn.t, JaResource.record) ::
Plug.Conn.t |
JaResource.record |
nil
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