MishkaGervaz.Table.Web.Events.RecordHandler behaviour
(MishkaGervaz v0.0.1-alpha.3)
Copy Markdown
View Source
Handles record operations for Events module.
This module provides functions for fetching, deleting, unarchiving, and permanently destroying records.
Customization
You can create a custom RecordHandler:
defmodule MyApp.CustomRecordHandler do
use MishkaGervaz.Table.Web.Events.RecordHandler
# Custom delete that adds audit logging
def delete_record(state, record) do
result = super(state, record)
MyApp.AuditLog.log_delete(record, state.current_user)
result
end
endThen configure it in your resource's DSL:
mishka_gervaz do
table do
events do
record MyApp.CustomRecordHandler
end
end
endSee MishkaGervaz.Table.Web.Events,
MishkaGervaz.Table.Web.DataLoader,
and the sibling handlers SanitizationHandler, SelectionHandler,
BulkActionHandler, HookRunner, RelationFilterHandler.
Summary
Callbacks
Deletes a record using the source destroy action.
Destroys a record with a specific Ash action.
Fetches a record by ID.
Permanently destroys an archived record.
Restores an archived record.
Updates a record with a specific Ash action.
Types
@type archive_status() :: :active | :archived
@type record() :: struct()
@type state() :: MishkaGervaz.Table.Web.State.t()
Callbacks
Deletes a record using the source destroy action.
Returns {:ok, deleted_record} or {:error, reason}.
@callback destroy_record( state :: state(), record :: record(), action :: atom() | {atom(), atom()} ) :: {:ok, record()} | {:error, term()}
Destroys a record with a specific Ash action.
The action can be an atom or tuple {master_action, tenant_action}.
Returns {:ok, destroyed_record} or {:error, reason}.
@callback get_record( state :: state(), id :: String.t(), archive_status :: archive_status() ) :: record()
Fetches a record by ID.
Uses the appropriate action based on archive status and user type.
@callback permanent_destroy_record(state :: state(), record :: record()) :: {:ok, record()} | {:error, term()}
Permanently destroys an archived record.
Returns {:ok, destroyed_record} or {:error, reason}.
@callback unarchive_record(state :: state(), record :: record()) :: {:ok, record()} | {:error, term()}
Restores an archived record.
Returns {:ok, restored_record} or {:error, reason}.
@callback update_record( state :: state(), record :: record(), action :: atom() | {atom(), atom()} ) :: {:ok, record()} | {:error, term()}
Updates a record with a specific Ash action.
The action can be an atom or tuple {master_action, tenant_action}.
Returns {:ok, updated_record} or {:error, reason}.