docs: update getting started guide

fix: don't require pagination
This commit is contained in:
Zach Daniel 2023-08-19 00:45:18 -04:00
parent 7a64c8f41c
commit 69b61103ae
2 changed files with 30 additions and 18 deletions

View file

@ -15,7 +15,7 @@ Ash Double Entry is implemented as a set of Ash resource extensions. You build t
#### Example #### Example
```elixir ```elixir
defmodule YourApp.Account do defmodule YourApp.Leger.Account do
use Ash.Resource, use Ash.Resource,
data_layer: AshPostgres.DataLayer, data_layer: AshPostgres.DataLayer,
extensions: [AshDoubleEntry.Account] extensions: [AshDoubleEntry.Account]
@ -27,8 +27,8 @@ defmodule YourApp.Account do
account do account do
# configure the other resources it will interact with # configure the other resources it will interact with
transfer_resource YourApp.Transfer transfer_resource YourApp.Ledger.Transfer
balance_resource YourApp.Balance balance_resource YourApp.Ledger.Balance
# accept custom attributes in the autogenerated `open` create action # accept custom attributes in the autogenerated `open` create action
open_action_accept [:account_number] open_action_accept [:account_number]
end end
@ -78,8 +78,8 @@ defmodule YourApp.Transfer do
transfer do transfer do
# configure the other resources it will interact with # configure the other resources it will interact with
account_resource YourApp.Account account_resource YourApp.Ledger.Account
balance_resource YourApp.Balance balance_resource YourApp.Ledger.Balance
end end
end end
``` ```
@ -102,7 +102,7 @@ end
#### Example #### Example
```elixir ```elixir
defmodule YourApp.Balance do defmodule YourApp.Ledger.Balance do
use Ash.Resource, use Ash.Resource,
data_layer: AshPostgres.DataLayer, data_layer: AshPostgres.DataLayer,
extensions: [AshDoubleEntry.Balance] extensions: [AshDoubleEntry.Balance]
@ -114,8 +114,8 @@ defmodule YourApp.Balance do
balance do balance do
# configure the other resources it will interact with # configure the other resources it will interact with
transfer_resource Transfer transfer_resource YourApp.Ledger.Transfer
account_resource Account account_resource YourApp.Ledger.Account
end end
changes do changes do
@ -162,40 +162,52 @@ defmodule YourApp.Ledger do
use Ash.Api use Ash.Api
resources do resources do
resource YourApp.Account resource YourApp.Ledger.Account
resource YourApp.Balance resource YourApp.Ledger.Balance
resource YourApp.Transfer resource YourApp.Ledger.Transfer
end end
end end
``` ```
And add the API to your config
`config :your_app, ash_apis: [..., YourApp.Ledger]
### Generate Migrations
`mix ash_postgres.generate_migrations --name add_double_entry_ledger`
### Run them
`mix ash_postgres.migrate`
### Use them ### Use them
#### Create an account #### Create an account
```elixir ```elixir
Account YourApp.Ledger.Account
|> Ash.Changeset.for_create(:open, %{identifier: "account_one", currency: "USD"}) |> Ash.Changeset.for_create(:open, %{identifier: "account_one", currency: "USD"})
|> Api.create!() |> YourApp.Ledger.create!()
``` ```
#### Create transfers between accounts #### Create transfers between accounts
```elixir ```elixir
Transfer YourApp.Ledger.Transfer
|> Ash.Changeset.for_create(:transfer, %{ |> Ash.Changeset.for_create(:transfer, %{
amount: Decimal.new(20), amount: Decimal.new(20),
from_account_id: account_one.id, from_account_id: account_one.id,
to_account_id: account_two.id to_account_id: account_two.id
}) })
|> Api.create!() |> YourApp.LedgerApi.create!()
``` ```
#### Check an account's balance #### Check an account's balance
```elixir ```elixir
Account YourApp.Leger.Account
|> Api.get!(account_id, load: :balance) |> YourApp.Ledger.get!(account_id, load: :balance)
|> Map.get(:balance) |> Map.get(:balance)
# => Decimal.new("20") # => Decimal.new("20")
``` ```

View file

@ -101,7 +101,7 @@ defmodule AshDoubleEntry.Account.Transformers.AddStructure do
else else
Ash.Resource.Builder.add_action(dsl, :read, :_autogenerated_primary_read, Ash.Resource.Builder.add_action(dsl, :read, :_autogenerated_primary_read,
primary?: true, primary?: true,
pagination: Ash.Resource.Builder.build_pagination(keyset?: true) pagination: Ash.Resource.Builder.build_pagination(keyset?: true, required?: false)
) )
end end
end end