accountv2

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const EventNameAccountOpened = "account/opened"

Variables

This section is empty.

Functions

func CustomSnapshot

func CustomSnapshot(
	ctx context.Context,
	root *Account,
	_, _ version.Version,
	_ aggregate.CommittedEvents[AccountEvent],
) bool

func NewEmptyMaker

func NewEmptyMaker(timeProvider timeutils.TimeProvider) func() *Account

Types

type Account

type Account struct {
	aggregate.Base
	// contains filtered or unexported fields
}

func Open

func Open(id AccountID, timeProvider timeutils.TimeProvider, holderName string) (*Account, error)

func (*Account) Apply

func (a *Account) Apply(evt AccountEvent) error

func (*Account) Balance

func (a *Account) Balance() int

func (*Account) DepositMoney

func (a *Account) DepositMoney(amount int) error

func (*Account) EventFuncs

func (a *Account) EventFuncs() event.FuncsFor[AccountEvent]

func (*Account) HolderName

func (a *Account) HolderName() string

func (*Account) ID

func (a *Account) ID() AccountID

func (*Account) WithdrawMoney

func (a *Account) WithdrawMoney(amount int) (int, error)

Returns the amount withdrawn and an error if any

type AccountEvent

type AccountEvent interface {
	event.Any
	shared.EventMeta
	// contains filtered or unexported methods
}

type AccountID

type AccountID string

func (AccountID) String

func (a AccountID) String() string

type AccountOutboxProcessor

type AccountOutboxProcessor struct{}

func NewAccountOutboxProcessor

func NewAccountOutboxProcessor(db *sql.DB) (*AccountOutboxProcessor, error)

func (*AccountOutboxProcessor) Process

func (p *AccountOutboxProcessor) Process(
	ctx context.Context,
	tx *sql.Tx,
	root *Account,
	committedEvents aggregate.CommittedEvents[AccountEvent],
) error

Process writes committed AccountEvents to the outbox table within the same transaction.

type AccountsWithNameProcessor

type AccountsWithNameProcessor struct{}

func NewAccountsWithNameProcessor

func NewAccountsWithNameProcessor(db *sql.DB) (*AccountsWithNameProcessor, error)

func (*AccountsWithNameProcessor) Process

type Snapshot

type Snapshot struct {
	AccountID        AccountID       `json:"id"`
	OpenedAt         time.Time       `json:"openedAt"`
	Balance          int             `json:"balance"`
	HolderName       string          `json:"holderName"`
	AggregateVersion version.Version `json:"version"`
}

func (*Snapshot) ID

func (s *Snapshot) ID() AccountID

func (*Snapshot) Version

func (s *Snapshot) Version() version.Version

type Snapshotter

type Snapshotter struct {
	TimeProvider timeutils.TimeProvider
}

func (*Snapshotter) FromSnapshot

func (s *Snapshotter) FromSnapshot(snap *Snapshot) (*Account, error)

func (*Snapshotter) ToSnapshot

func (s *Snapshotter) ToSnapshot(acc *Account) (*Snapshot, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL