domain

package
v0.0.0-...-3a9fddd Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderCreatedEvent   = "ordering.OrderCreated"
	OrderCanceledEvent  = "ordering.OrderCanceled"
	OrderReadiedEvent   = "ordering.OrderReadied"
	OrderCompletedEvent = "ordering.OrderCompleted"
)
View Source
const OrderAggregate = "ordering.Order"

Variables

View Source
var (
	ErrOrderAlreadyCreated     = errors.Wrap(errors.ErrBadRequest, "the order cannot be recreated")
	ErrOrderHasNoItems         = errors.Wrap(errors.ErrBadRequest, "the order has no items")
	ErrOrderCannotBeCancelled  = errors.Wrap(errors.ErrBadRequest, "the order cannot be cancelled")
	ErrCustomerIDCannotBeBlank = errors.Wrap(errors.ErrBadRequest, "the customer id cannot be blank")
	ErrPaymentIDCannotBeBlank  = errors.Wrap(errors.ErrBadRequest, "the payment id cannot be blank")
)

Functions

This section is empty.

Types

type CustomerRepository

type CustomerRepository interface {
	Authorize(ctx context.Context, customerID string) error
}

type InvoiceRepository

type InvoiceRepository interface {
	Save(ctx context.Context, orderID, paymentID string, amount float64) error
	Delete(ctx context.Context, invoiceID string) error
}

type Item

type Item struct {
	ProductID   string
	StoreID     string
	StoreName   string
	ProductName string
	Price       float64
	Quantity    int
}

type NotificationRepository

type NotificationRepository interface {
	NotifyOrderCreated(ctx context.Context, orderID, customerID string) error
	NotifyOrderCanceled(ctx context.Context, orderID, customerID string) error
	NotifyOrderReady(ctx context.Context, orderID, customerID string) error
}

type Order

type Order struct {
	es.Aggregate
	CustomerID string
	PaymentID  string
	InvoiceID  string
	ShoppingID string
	Items      []Item
	Status     OrderStatus
}

func NewOrder

func NewOrder(id string) *Order

func (*Order) ApplyEvent

func (o *Order) ApplyEvent(event ddd.Event) error

func (*Order) ApplySnapshot

func (o *Order) ApplySnapshot(snapshot es.Snapshot) error

func (*Order) Cancel

func (o *Order) Cancel() error

func (*Order) Complete

func (o *Order) Complete(invoiceID string) error

func (*Order) CreateOrder

func (o *Order) CreateOrder(id, customerID, paymentID, shoppingID string, items []Item) error

func (Order) GetTotal

func (o Order) GetTotal() float64

func (Order) Key

func (Order) Key() string

func (*Order) Ready

func (o *Order) Ready() error

func (*Order) ToSnapshot

func (o *Order) ToSnapshot() es.Snapshot

type OrderCanceled

type OrderCanceled struct {
	CustomerID string
}

func (OrderCanceled) Key

func (OrderCanceled) Key() string

type OrderCompleted

type OrderCompleted struct {
	InvoiceID string
}

func (OrderCompleted) Key

func (OrderCompleted) Key() string

type OrderCreated

type OrderCreated struct {
	CustomerID string
	PaymentID  string
	ShoppingID string
	Items      []Item
}

func (OrderCreated) Key

func (OrderCreated) Key() string

type OrderReadied

type OrderReadied struct {
	CustomerID string
	PaymentID  string
	Total      float64
}

func (OrderReadied) Key

func (OrderReadied) Key() string

type OrderRepository

type OrderRepository interface {
	Load(ctx context.Context, orderID string) (*Order, error)
	Save(ctx context.Context, order *Order) error
}

type OrderStatus

type OrderStatus string
const (
	OrderUnknown     OrderStatus = ""
	OrderIsPending   OrderStatus = "pending"
	OrderIsInProcess OrderStatus = "in-progress"
	OrderIsReady     OrderStatus = "ready"
	OrderIsCompleted OrderStatus = "completed"
	OrderIsCancelled OrderStatus = "cancelled"
)

func ToOrderStatus

func ToOrderStatus(status string) OrderStatus

func (OrderStatus) String

func (s OrderStatus) String() string

type OrderV1

type OrderV1 struct {
	CustomerID string
	PaymentID  string
	InvoiceID  string
	ShoppingID string
	Items      []Item
	Status     OrderStatus
}

func (OrderV1) SnapshotName

func (OrderV1) SnapshotName() string

type PaymentRepository

type PaymentRepository interface {
	Confirm(ctx context.Context, paymentID string) error
}

type ShoppingRepository

type ShoppingRepository interface {
	Create(ctx context.Context, orderID string, items []Item) (string, error)
	Cancel(ctx context.Context, shoppingID string) error
}

Jump to

Keyboard shortcuts

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