model

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateReference

func GenerateReference() string

GenerateReference generates a random reference using UUID

func IsSKU

func IsSKU(input string) bool

IsSKU checks if the input string is an SKU

Types

type AddItemsRequest

type AddItemsRequest struct {
	Items []*Item `json:"items"`
}

type HealthResponse

type HealthResponse struct {
	Version  string   `json:"version,omitempty"`
	Service  string   `json:"service,omitempty"`
	Failures []string `json:"failures"`
}

HealthResponse contains health probe response fields.

type Item

type Item struct {
	ID    int             `json:"id,omitempty" gorm:"primaryKey;type:integer"`
	SKU   string          `json:"sku" gorm:"column:sku;type:string;unique"`
	Name  string          `json:"name" gorm:"column:name;type:string;unique"`
	Price decimal.Decimal `json:"price" gorm:"column:price;type:numeric(12,2)"`
	// InventoryQuantity adds a non-zero check at the DB level
	InventoryQuantity int `` /* 128-byte string literal not displayed */
}

func (*Item) TableName

func (i *Item) TableName() string

func (*Item) Validate

func (i *Item) Validate() error

type ItemsPriceRequest

type ItemsPriceRequest struct {
	SKUs []string `json:"skus"`
}

type Notification added in v0.7.0

type Notification struct {
	EventID    string    `json:"event_id"`
	Reference  string    `json:"reference"`
	CustomerID string    `json:"customer_id"`
	OccurredAt time.Time `json:"occurred_at"`
	Delivered  bool      `json:"delivered"`
}

Notification is a rendered order event ready to be delivered to a client.

type Order

type Order struct {
	ID         int             `json:"id,omitempty" gorm:"primaryKey;type:integer"`
	Reference  string          `json:"reference" gorm:"column:reference;type:string;uniqueIndex"` // Unique random reference
	CustomerID string          `json:"customer_id" gorm:"column:customer_id;type:text"`
	SKUList    string          `json:"sku_list" gorm:"column:sku_list;type:text"`
	Price      decimal.Decimal `json:"price" gorm:"column:price;type:numeric(12,2)"`
}

func (*Order) GetSKUList

func (o *Order) GetSKUList() ([]string, error)

GetSKUList returns the SKU list as a slice of strings

func (*Order) SetSKUList

func (o *Order) SetSKUList(skuList []string) error

SetSKUList sets the SKU list from a slice of strings

func (*Order) TableName

func (o *Order) TableName() string

type Orders

type Orders []Order

type OutboxItem added in v0.7.0

type OutboxItem struct {
	// ID is assigned by the database sequence, not the application. It gives
	// the relay a stable, monotonic handle for a specific row. It is a physical
	// ordering handle only — never the broker key or the dedup key; EventID is
	// the business identity.
	ID int64 `json:"id,omitempty" gorm:"primaryKey;autoIncrement"`

	// EventID is the business identity consumers deduplicate on. Unique so a
	// retried producer transaction cannot enqueue the same event twice.
	EventID string `json:"event_id" gorm:"column:event_id;uniqueIndex"`

	// Topic and PartitionKey are the broker routing metadata. They are columns
	// rather than fields inside Data so the relay can route without decoding the
	// payload.
	Topic        string `json:"topic" gorm:"column:topic"`
	PartitionKey string `json:"partition_key" gorm:"column:partition_key"`

	// Data is the encoded event value, shipped to the broker as-is.
	Data []byte `json:"data" gorm:"column:data"`

	// OccurredAt is when the event happened; CreatedAt is when the row was
	// enqueued. The relay does not read these, but they support retention and
	// debugging.
	OccurredAt time.Time `json:"occurred_at" gorm:"column:occurred_at"`
	CreatedAt  time.Time `json:"created_at" gorm:"column:created_at;autoCreateTime"`

	// PublishedAt and DeliveredAt are nil until the respective milestone is
	// reached. They MUST be pointers: a zero time.Time is a real timestamp, not
	// "not yet", so a non-pointer field could never express an unpublished row
	// and the relay's "WHERE published_at IS NULL" scan would match nothing.
	PublishedAt *time.Time `json:"published_at,omitempty" gorm:"column:published_at;index"`
	DeliveredAt *time.Time `json:"delivered_at,omitempty" gorm:"column:delivered_at"`
}

OutboxItem is one row of the transactional outbox. It is written in the same database transaction as the business change it describes, then drained to the message broker by a separate relay. The relay routes on Topic and PartitionKey and ships Data verbatim as the record value.

func (*OutboxItem) TableName added in v0.7.0

func (o *OutboxItem) TableName() string

type OutboxItems added in v0.7.0

type OutboxItems []OutboxItem

type PriceResponse

type PriceResponse struct {
	Items             []*Item     `json:"items"`
	Promotions        *Promotions `json:"promotions,omitempty"`
	TotalGross        float64     `json:"total_gross"`
	TotalWithDiscount float64     `json:"total_with_discount"`
}

type Promotions

type Promotions struct {
	Deduction  float64 `json:"deduction"`
	AddedItems []*Item `json:"added_items"`
}

type PurchaseItemsRequest

type PurchaseItemsRequest struct {
	SKUs []string `json:"skus"`
}

type PurchaseItemsResponse

type PurchaseItemsResponse struct {
	OrderReference string  `json:"order_reference"`
	Cost           float64 `json:"cost"`
}

type StatusResponse

type StatusResponse struct {
	Message string `json:"message,omitempty"`
	Version string `json:"version,omitempty"`
	Service string `json:"service,omitempty"`
}

StatusResponse contains status response fields.

Jump to

Keyboard shortcuts

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