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 ¶
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 ¶
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 ¶
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.