DoubleEntryLedger.JournalEvent (double_entry_ledger v0.1.0)
View SourceDefines and manages JournalEvents in the Double Entry Ledger system.
JournalEvents are immutable facts of the ledger. Replaying these JournalEvents will recreate the ledger.
Summary
Functions
Creates a changeset for validating and creating JournalEvents.
Types
@type t() :: %DoubleEntryLedger.JournalEvent{ __meta__: term(), account: DoubleEntryLedger.Account.t() | Ecto.Association.NotLoaded.t() | nil, command: DoubleEntryLedger.Command.t() | Ecto.Association.NotLoaded.t() | nil, command_map: map() | nil, id: Ecto.UUID.t() | nil, inserted_at: DateTime.t() | nil, instance: DoubleEntryLedger.Instance.t() | Ecto.Association.NotLoaded.t(), instance_id: Ecto.UUID.t() | nil, journal_event_account_link: DoubleEntryLedger.JournalEventAccountLink.t() | Ecto.Association.NotLoaded.t() | nil, journal_event_command_link: DoubleEntryLedger.JournalEventCommandLink.t() | Ecto.Association.NotLoaded.t() | nil, journal_event_transaction_link: DoubleEntryLedger.JournalEventTransactionLink.t() | Ecto.Association.NotLoaded.t() | nil, transaction: DoubleEntryLedger.Transaction.t() | Ecto.Association.NotLoaded.t() | nil, updated_at: DateTime.t() | nil }
Functions
@spec build_create(map()) :: Ecto.Changeset.t(t())
Creates a changeset for validating and creating JournalEvents.
Parameters
event- The Command struct to create a changeset forattrs- Map of attributes to apply to the event
Returns
- An Ecto.Changeset with validations applied
Examples
# Create event changeset
iex> command_map = %{
...> action: :create_transaction,
...> source: "api",
...> source_idempk: "order-123",
...> instance_address: "instance1",
...> payload: %{status: :pending, entries: [
...> %{account_address: "account1", amount: 100, currency: :USD},
...> %{account_address: "account2", amount: 100, currency: :USD}
...> ]}
...> }
...> attrs = %{instance_id: Ecto.UUID.generate(), command_map: command_map}
iex> changeset = JournalEvent.changeset(%Command{}, attrs)
iex> changeset.valid?
true