orders

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: 20 Imported by: 0

Documentation

Overview

@title Checkout Orders Service API @version 1.0 @description API for managing inventory and orders @host localhost:8000 @BasePath /

Index

Constants

View Source
const ServiceName = "orders service"
View Source
const TopicOrderCreated = "orders.created"

TopicOrderCreated carries an event per completed purchase order.

Variables

View Source
var (
	ItemsEndPnt        = "/v1/inventory/items"
	ItemPriceEndPnt    = "/v1/inventory/item/price"
	ItemsPriceEndPnt   = "/v1/inventory/items/price"
	ItemPurchaseEndPnt = "/v1/inventory/items/purchase"
	KeyParam           = "/:key"

	OrdersEndPnt = "/v1/orders"
)

Functions

This section is empty.

Types

type Option

type Option func(*OutboxRelayer)

Option configures an OutboxRelayer.

func WithBatchSize

func WithBatchSize(n int) Option

WithBatchSize overrides how many rows are claimed per scan.

func WithPollInterval

func WithPollInterval(d time.Duration) Option

WithPollInterval overrides how often the relay scans the outbox when idle.

type OutboxRelayer

type OutboxRelayer struct {
	// contains filtered or unexported fields
}

OutboxRelayer polls the outbox for unpublished rows and publishes them to the broker, marking each published on success. It closes the loop opened by the purchase handler writing an outbox row inside the order transaction: durability lives in the table, so an unpublished row simply waits for the next scan (or the next process start) rather than being lost.

func NewOutboxRelayer

func NewOutboxRelayer(store database.OutboxStore, publisher messaging.Publisher, opts ...Option) *OutboxRelayer

NewOutboxRelayer builds a relayer over the given store and publisher.

func (*OutboxRelayer) Ping

func (o *OutboxRelayer) Ping(ctx context.Context) error

Ping reports broker reachability, for the service health probe.

func (*OutboxRelayer) Start

func (o *OutboxRelayer) Start(startCtx context.Context) error

Start launches the poll loop. startCtx bounds a fail-fast connectivity check only; the loop is torn down via Stop (worker.Runner cancellation).

func (*OutboxRelayer) Stop

func (o *OutboxRelayer) Stop() error

Stop terminates the poll loop and closes the publisher. The Runner's Stop is idempotent and blocks until the loop goroutine has returned.

type Relayer

type Relayer interface {
	Start(ctx context.Context) error
	Stop() error
	Ping(ctx context.Context) error
}

Relayer drains the transactional outbox to the message broker. It is a long-lived background process: Start spawns its goroutine, Stop terminates it.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service executes business logic covering order and inventory, handles requests, and provides access to the connected Database.

func NewService

func NewService(db store,
	relayer Relayer,
	authn auth.Authenticator,
) *Service

NewService constructs the orders domain service. The listening port is not its concern — the httpserver that wraps it owns that.

func (*Service) AddItems

func (h *Service) AddItems() httprouter.Handle

AddItems godoc @Summary Add new or updated items to the inventory table @Description Add new or updated items @Tags inventory @Accept json @Produce json @Param request body model.AddItemsRequest true "List of items" @Success 200 {array} model.Item @Failure 400 {object} errors.JSONError @Failure 401 {object} errors.JSONError @Failure 404 {object} errors.JSONError @Failure 500 {object} errors.JSONError @Security XAuthPassword @Router /v1/inventory/items [post]

func (*Service) ItemPrice

func (h *Service) ItemPrice() httprouter.Handle

ItemPrice godoc @Summary Get price for a single item @Description Get price information for a single item by SKU or name @Tags inventory @Produce json @Param key path string true "Item SKU or Name" @Success 200 {object} model.PriceResponse @Failure 400 {object} errors.JSONError @Failure 404 {object} errors.JSONError @Failure 500 {object} errors.JSONError @Router /v1/inventory/item/price/{key} [get]

func (*Service) ItemsPrice

func (h *Service) ItemsPrice() httprouter.Handle

ItemsPrice godoc @Summary Get prices for multiple items @Description Get total price for a batch of items by SKUs @Tags inventory @Accept json @Produce json @Param request body model.ItemsPriceRequest true "List of SKUs" @Success 200 {object} model.PriceResponse @Failure 400 {object} errors.JSONError @Failure 404 {object} errors.JSONError @Failure 500 {object} errors.JSONError @Router /v1/inventory/items/price [post]

func (*Service) ListItems

func (h *Service) ListItems() httprouter.Handle

ListItems godoc @Summary Returns a list of items in the inventory table @Description Show all listed inventory items @Tags inventory @Produce json @Success 200 {array} model.Item @Failure 500 {object} errors.JSONError @Security XAuthPassword @Router /v1/inventory/items [get]

func (*Service) Orders

func (h *Service) Orders() httprouter.Handle

Orders godoc @Summary Get list of purchase orders @Description List all purchase orders @Tags inventory @Produce json @Success 200 {array} model.Order @Failure 400 {object} errors.JSONError @Failure 401 {object} errors.JSONError @Failure 404 {object} errors.JSONError @Failure 500 {object} errors.JSONError @Security XAuthPassword @Router /v1/orders [get]

func (*Service) PurchaseItems

func (h *Service) PurchaseItems() httprouter.Handle

PurchaseItems godoc @Summary Execute a purchase for the supplied item list. @Description Create a purchase order for the supplied item list. @Tags inventory @Accept json @Produce json @Param request body model.PurchaseItemsRequest true "List of SKUs" @Success 200 {object} model.PurchaseItemsResponse @Failure 400 {object} errors.JSONError @Failure 404 {object} errors.JSONError @Failure 503 {object} errors.JSONError @Security XAuthPassword @Router /v1/inventory/items/purchase [post]

func (*Service) RegisterHandlers

func (h *Service) RegisterHandlers() *httprouter.Router

func (*Service) Start

func (h *Service) Start(ctx context.Context) error

Start boots the service's background processes (the outbox relay).

func (*Service) Stop

func (h *Service) Stop() error

Stop tears down the background processes started by Start.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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