Documentation
¶
Index ¶
- func GenerateCategoryID() (string, error)
- func GenerateCollectionID() (string, error)
- func GenerateProductID() (string, error)
- func GenerateSlug(name string) string
- func GetCategorySlug(categoryID string) string
- func ValidateCategoryName(name string) error
- func ValidateCollectionName(name string) error
- func ValidateDisplayOrder(order int) error
- func ValidateInventoryStatus(status string) error
- func ValidatePrice(price float64) error
- func ValidateSKU(sku string) error
- func ValidateSlug(slug string) error
- func ValidateTitle(title string) error
- type Category
- type CategoryMutation
- type CategoryTree
- type Collection
- type CollectionMutation
- type Product
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateCategoryID ¶
GenerateCategoryID generates a unique category ID in format: cat_[base62]
func GenerateCollectionID ¶
GenerateCollectionID generates a unique collection ID in format: col_[base62]
func GenerateProductID ¶
GenerateProductID generates a unique product ID in format: prod_[base62]
func GenerateSlug ¶
GenerateSlug creates a URL-friendly slug from a category name
func GetCategorySlug ¶
GetCategorySlug extracts the category slug from category ID Assumes format: cat_[slug]
func ValidateCategoryName ¶
ValidateCategoryName checks if category name is valid
func ValidateCollectionName ¶
ValidateCollectionName checks if collection name is valid
func ValidateDisplayOrder ¶
ValidateDisplayOrder checks if display order is valid
func ValidateInventoryStatus ¶
ValidateInventoryStatus checks if inventory status is valid
Types ¶
type Category ¶
type Category struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
ParentID *string `json:"parent_id,omitempty"`
DisplayOrder int `json:"display_order"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Computed fields (not in YAML)
Parent *Category `json:"-"`
Children []*Category `json:"-"`
Path []*Category `json:"-"` // Root to current
Depth int `json:"-"`
}
Category represents a hierarchical product category
func (*Category) GetAncestorIDs ¶
GetAncestorIDs returns all ancestor category IDs from root to parent
func (*Category) GetDescendantIDs ¶
GetDescendantIDs returns all descendant category IDs recursively
func (*Category) HasChildren ¶
HasChildren returns true if this category has child categories
type CategoryMutation ¶
type CategoryMutation struct {
ID string
Name string
Slug string
ParentID *string
DisplayOrder int
Body string
CreatedAt time.Time
UpdatedAt time.Time
}
CategoryMutation represents a category for mutation operations
func NewCategory ¶
func NewCategory(name, slug string, parentID *string, displayOrder int) (*CategoryMutation, error)
NewCategory creates a new category with generated ID and timestamps
func (*CategoryMutation) Validate ¶
func (c *CategoryMutation) Validate() error
Validate performs comprehensive validation on the category
type CategoryTree ¶
type CategoryTree struct {
// contains filtered or unexported fields
}
CategoryTree builds and manages the hierarchical category structure
func NewCategoryTree ¶
func NewCategoryTree() *CategoryTree
NewCategoryTree creates a new category tree builder
func (*CategoryTree) AddCategory ¶
func (t *CategoryTree) AddCategory(cat *Category)
AddCategory adds a category to the tree
func (*CategoryTree) Build ¶
func (t *CategoryTree) Build()
Build constructs the hierarchical relationships
func (*CategoryTree) GetAll ¶
func (t *CategoryTree) GetAll() []*Category
GetAll returns all categories
func (*CategoryTree) GetCategory ¶
func (t *CategoryTree) GetCategory(id string) (*Category, bool)
GetCategory returns a category by ID
func (*CategoryTree) GetFlatList ¶
func (t *CategoryTree) GetFlatList() []*Category
GetFlatList returns all categories in a flat list sorted by display order
func (*CategoryTree) GetRoots ¶
func (t *CategoryTree) GetRoots() []*Category
GetRoots returns all root categories sorted by display order
type Collection ¶
type Collection struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
DisplayOrder int `json:"display_order"`
ProductIDs []string `json:"product_ids"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Collection represents a flat grouping of products
func (*Collection) ContainsProduct ¶
func (c *Collection) ContainsProduct(productID string) bool
ContainsProduct returns true if the collection contains the given product ID
func (*Collection) ProductCount ¶
func (c *Collection) ProductCount() int
ProductCount returns the number of products in this collection
type CollectionMutation ¶
type CollectionMutation struct {
ID string
Name string
Slug string
DisplayOrder int
Body string
CreatedAt time.Time
UpdatedAt time.Time
}
CollectionMutation represents a collection for mutation operations
func NewCollection ¶
func NewCollection(name, slug string, displayOrder int) (*CollectionMutation, error)
NewCollection creates a new collection with generated ID and timestamps
func (*CollectionMutation) Validate ¶
func (c *CollectionMutation) Validate() error
Validate performs comprehensive validation on the collection
type Product ¶
type Product struct {
ID string
SKU string
Title string
Body string
Price float64
Currency string
InventoryStatus string
InventoryQuantity *int
CategoryID string
CollectionIDs []string
Images []string
Metadata map[string]interface{}
CreatedAt time.Time
UpdatedAt time.Time
}
Product represents a sellable item in the catalog