order

package
v0.0.0-...-c3821dc Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Completed

type Completed struct{}

Completed - the order is fully paid

type Created

type Created struct {
	Total uint
}

Created when the order was created

type DiscountApplied

type DiscountApplied struct {
	Percentage uint
	Total      uint
}

DiscountApplied when a discount was applied

type DiscountRemoved

type DiscountRemoved struct{}

DiscountRemoved when the discount was removed

type Order

type Order struct {
	aggregate.Root
	Status      Status
	Total       uint
	Discount    uint
	Outstanding uint
	Paid        uint
}

Order is the aggregate protecting the state

func Create

func Create(amount uint) (*Order, error)

Create creates the initial order

func (*Order) AddDiscount

func (o *Order) AddDiscount(percentage uint) error

AddDiscount adds discount to the order

func (*Order) Pay

func (o *Order) Pay(amount uint) error

Pay creates a payment on the order. If the outstanding amount is zero the order is paid.

func (*Order) Register

func (o *Order) Register(r aggregate.RegisterFunc)

Register is a eventsouring helper function that must be defined on the aggregate.

func (*Order) RemoveDiscount

func (o *Order) RemoveDiscount()

RemoveDiscount removes the discount if any otherwise ignore

func (*Order) Transition

func (o *Order) Transition(event eventsourcing.Event)

Transition builds the aggregate state based on the events

type Paid struct {
	Amount uint
}

Paid an amount from the total

type Status

type Status string
const (
	Pending  Status = "pending"
	Complete Status = "complete"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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