api

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 10 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api hosts the catalog module's HTTP surfaces: the admin product-commerce endpoints (protected realm) and the public product payload (anonymous realm). Both write through kernel/httpx — this is a new surface with no legacy envelope contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	PostType string
	Currency string
}

Config carries the operator knobs the handlers need: which post type is the catalog product type, and the display currency for public payloads.

type Handler

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

Handler serves both catalog realms; New builds it once so the admin and public surfaces share the adopted service.

func New

func New(
	service *catalogdomain.Service,
	config Config,
	postTypes PostTypeChecker,
	slug ProductSlugResolver,
	resolve kernel.CapabilityResolver,
) *Handler

New builds the handler. The capability resolver gates admin mutations (nil resolver denies every mutation — fail closed); the post-type checker and slug resolver come from the composition root.

func (*Handler) GetProduct

func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request)

GetProduct handles GET /catalog/products/{contentID}: the stored commerce data for one product, or 404 when the item carries none.

func (*Handler) GetPublicProduct

func (h *Handler) GetPublicProduct(w http.ResponseWriter, r *http.Request)

GetPublicProduct handles GET /catalog/products/{slug} on the public router: the commerce payload for a published product, or 404 when the slug is unknown, unpublished, or carries no catalog data.

func (*Handler) UpsertProduct

func (h *Handler) UpsertProduct(w http.ResponseWriter, r *http.Request)

UpsertProduct handles PUT /catalog/products/{contentID}: validates and writes the commerce data, replacing the variant matrix. Gated to the admin capability for now — the catalog.manage capability is contributed via RoleProvider so a role-registry grants mechanism can widen access later without changing this surface's wire behavior.

type PostTypeChecker

type PostTypeChecker interface {
	Exists(slug string) bool
}

PostTypeChecker reports whether a post-type slug is registered. Satisfied by the composition root over the post-type registry; the module fails startup closed when its configured product type is missing.

type ProductSlugResolver

type ProductSlugResolver func(ctx context.Context, slug string) (contentID int, found bool)

ProductSlugResolver resolves a published product slug to its content ID. Satisfied by the composition root over the content service's published lookup; unpublished or unknown slugs resolve to not-found.

type PublicProduct

type PublicProduct struct {
	ContentID int                 `json:"contentId"`
	SKU       string              `json:"sku,omitempty"`
	Currency  string              `json:"currency"`
	Price     int64               `json:"price"`
	SalePrice *int64              `json:"salePrice,omitempty"`
	InStock   bool                `json:"inStock"`
	LowStock  bool                `json:"lowStock,omitempty"`
	Stock     int                 `json:"stock,omitempty"`
	Options   map[string][]string `json:"options,omitempty"`
	Variants  []PublicVariant     `json:"variants,omitempty"`
}

PublicProduct is the commerce payload themes and headless frontends consume: pricing (minor units), stock posture, and the variant matrix with resolved effective prices.

type PublicVariant

type PublicVariant struct {
	ID       int64             `json:"id"`
	Options  map[string]string `json:"options"`
	SKU      string            `json:"sku,omitempty"`
	Price    int64             `json:"price"`
	InStock  bool              `json:"inStock"`
	ImageURL string            `json:"imageUrl,omitempty"`
}

PublicVariant is one matrix entry in the public payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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