mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
improvement: add callbacks for bulk actions on manual actions
This commit is contained in:
parent
ed887413d7
commit
0932cf32a7
6 changed files with 77 additions and 6 deletions
|
@ -903,6 +903,18 @@ defmodule Ash.Actions.Create.Bulk do
|
|||
must_return_records_for_changes?,
|
||||
tenant: opts[:tenant]
|
||||
})
|
||||
|> Enum.flat_map(fn
|
||||
{:ok, result} ->
|
||||
[result]
|
||||
|
||||
{:error, error} ->
|
||||
store_error(ref, error, opts)
|
||||
[]
|
||||
|
||||
{:notifications, notifications} ->
|
||||
store_notification(ref, notifications, opts)
|
||||
[]
|
||||
end)
|
||||
else
|
||||
[changeset] = batch
|
||||
|
||||
|
|
|
@ -864,6 +864,18 @@ defmodule Ash.Actions.Destroy.Bulk do
|
|||
must_return_records_for_changes?,
|
||||
tenant: opts[:tenant]
|
||||
})
|
||||
|> Enum.flat_map(fn
|
||||
{:ok, result} ->
|
||||
[result]
|
||||
|
||||
{:error, error} ->
|
||||
store_error(ref, error, opts)
|
||||
[]
|
||||
|
||||
{:notifications, notifications} ->
|
||||
store_notification(ref, notifications, opts)
|
||||
[]
|
||||
end)
|
||||
else
|
||||
[changeset] = batch
|
||||
|
||||
|
@ -924,9 +936,6 @@ defmodule Ash.Actions.Destroy.Bulk do
|
|||
{:ok, result} ->
|
||||
result
|
||||
|
||||
:ok ->
|
||||
[]
|
||||
|
||||
{:error, error} ->
|
||||
store_error(ref, error, opts)
|
||||
[]
|
||||
|
|
|
@ -919,6 +919,18 @@ defmodule Ash.Actions.Update.Bulk do
|
|||
tenant: opts[:tenant]
|
||||
}
|
||||
])
|
||||
|> Enum.flat_map(fn
|
||||
{:ok, result} ->
|
||||
[result]
|
||||
|
||||
{:error, error} ->
|
||||
store_error(ref, error, opts)
|
||||
[]
|
||||
|
||||
{:notifications, notifications} ->
|
||||
store_notification(ref, notifications, opts)
|
||||
[]
|
||||
end)
|
||||
else
|
||||
[changeset] = batch
|
||||
|
||||
|
@ -977,9 +989,6 @@ defmodule Ash.Actions.Update.Bulk do
|
|||
{:ok, result} ->
|
||||
result
|
||||
|
||||
:ok ->
|
||||
[]
|
||||
|
||||
{:error, error} ->
|
||||
store_error(ref, error, opts)
|
||||
[]
|
||||
|
|
|
@ -21,6 +21,19 @@ defmodule Ash.Resource.ManualCreate do
|
|||
| {:ok, Ash.Resource.record(), %{notifications: [Ash.Notifier.Notification.t()]}}
|
||||
| {:error, term}
|
||||
|
||||
@callback bulk_create(
|
||||
changesets :: Enumerable.t(Ash.Changeset.t()),
|
||||
opts :: Keyword.t(),
|
||||
context :: context()
|
||||
) ::
|
||||
list(
|
||||
{:ok, Ash.Resource.record()}
|
||||
| {:error, Ash.Error.t()}
|
||||
| {:notifications, list(Ash.Notifier.Notification.t())}
|
||||
)
|
||||
|
||||
@optional_callbacks [bulk_create: 3]
|
||||
|
||||
defmacro __using__(_) do
|
||||
quote do
|
||||
@behaviour Ash.Resource.ManualCreate
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
defmodule Ash.Resource.ManualDestroy do
|
||||
@moduledoc """
|
||||
A module to implement manual destroy actions.
|
||||
|
||||
Note that in the returns of these functions you must return the destroyed record or records.
|
||||
"""
|
||||
|
||||
@type context :: %{
|
||||
|
@ -20,6 +22,19 @@ defmodule Ash.Resource.ManualDestroy do
|
|||
| {:ok, Ash.Resource.record(), list(Ash.Notifier.Notification.t())}
|
||||
| {:error, term}
|
||||
|
||||
@callback bulk_destroy(
|
||||
changesets :: Enumerable.t(Ash.Changeset.t()),
|
||||
opts :: Keyword.t(),
|
||||
context :: context()
|
||||
) ::
|
||||
list(
|
||||
{:ok, Ash.Resource.record()}
|
||||
| {:error, Ash.Error.t()}
|
||||
| {:notifications, list(Ash.Notifier.Notification.t())}
|
||||
)
|
||||
|
||||
@optional_callbacks [bulk_destroy: 3]
|
||||
|
||||
defmacro __using__(_) do
|
||||
quote do
|
||||
@behaviour Ash.Resource.ManualDestroy
|
||||
|
|
|
@ -20,6 +20,19 @@ defmodule Ash.Resource.ManualUpdate do
|
|||
| {:ok, Ash.Resource.record(), %{notifications: [Ash.Notifier.Notification.t()]}}
|
||||
| {:error, term}
|
||||
|
||||
@callback bulk_update(
|
||||
changesets :: Enumerable.t(Ash.Changeset.t()),
|
||||
opts :: Keyword.t(),
|
||||
context :: context()
|
||||
) ::
|
||||
list(
|
||||
{:ok, Ash.Resource.record()}
|
||||
| {:error, Ash.Error.t()}
|
||||
| {:notifications, list(Ash.Notifier.Notification.t())}
|
||||
)
|
||||
|
||||
@optional_callbacks [bulk_update: 3]
|
||||
|
||||
defmacro __using__(_) do
|
||||
quote do
|
||||
@behaviour Ash.Resource.ManualUpdate
|
||||
|
|
Loading…
Reference in a new issue