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
end

Then configure it in your resource's DSL:

mishka_gervaz do
  table do
    events do
      record MyApp.CustomRecordHandler
    end
  end
end

See 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

archive_status()

@type archive_status() :: :active | :archived

record()

@type record() :: struct()

state()

@type state() :: MishkaGervaz.Table.Web.State.t()

Callbacks

delete_record(state, record)

@callback delete_record(state :: state(), record :: record()) ::
  {:ok, record()} | {:error, term()}

Deletes a record using the source destroy action.

Returns {:ok, deleted_record} or {:error, reason}.

destroy_record(state, record, action)

@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}.

get_record(state, id, archive_status)

@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.

permanent_destroy_record(state, record)

@callback permanent_destroy_record(state :: state(), record :: record()) ::
  {:ok, record()} | {:error, term()}

Permanently destroys an archived record.

Returns {:ok, destroyed_record} or {:error, reason}.

unarchive_record(state, record)

@callback unarchive_record(state :: state(), record :: record()) ::
  {:ok, record()} | {:error, term()}

Restores an archived record.

Returns {:ok, restored_record} or {:error, reason}.

update_record(state, record, action)

@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}.