Documentation
¶
Overview ¶
@title Checkout Orders Service API @version 1.0 @description API for managing inventory and orders @host localhost:8000 @BasePath /
Index ¶
- Constants
- Variables
- type Option
- type OutboxRelayer
- type Relayer
- type Service
- func (h *Service) AddItems() httprouter.Handle
- func (h *Service) ItemPrice() httprouter.Handle
- func (h *Service) ItemsPrice() httprouter.Handle
- func (h *Service) ListItems() httprouter.Handle
- func (h *Service) Orders() httprouter.Handle
- func (h *Service) PurchaseItems() httprouter.Handle
- func (h *Service) RegisterHandlers() *httprouter.Router
- func (h *Service) Start(ctx context.Context) error
- func (h *Service) Stop() error
Constants ¶
const ServiceName = "orders service"
const TopicOrderCreated = "orders.created"
TopicOrderCreated carries an event per completed purchase order.
Variables ¶
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 ¶
WithBatchSize overrides how many rows are claimed per scan.
func WithPollInterval ¶
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