models

package
v0.0.0-...-74adf86 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCategoryID

func GenerateCategoryID() (string, error)

GenerateCategoryID generates a unique category ID in format: cat_[base62]

func GenerateCollectionID

func GenerateCollectionID() (string, error)

GenerateCollectionID generates a unique collection ID in format: col_[base62]

func GenerateProductID

func GenerateProductID() (string, error)

GenerateProductID generates a unique product ID in format: prod_[base62]

func GenerateSlug

func GenerateSlug(name string) string

GenerateSlug creates a URL-friendly slug from a category name

func GetCategorySlug

func GetCategorySlug(categoryID string) string

GetCategorySlug extracts the category slug from category ID Assumes format: cat_[slug]

func ValidateCategoryName

func ValidateCategoryName(name string) error

ValidateCategoryName checks if category name is valid

func ValidateCollectionName

func ValidateCollectionName(name string) error

ValidateCollectionName checks if collection name is valid

func ValidateDisplayOrder

func ValidateDisplayOrder(order int) error

ValidateDisplayOrder checks if display order is valid

func ValidateInventoryStatus

func ValidateInventoryStatus(status string) error

ValidateInventoryStatus checks if inventory status is valid

func ValidatePrice

func ValidatePrice(price float64) error

ValidatePrice checks if price is valid

func ValidateSKU

func ValidateSKU(sku string) error

ValidateSKU checks if SKU is valid

func ValidateSlug

func ValidateSlug(slug string) error

ValidateSlug checks if slug is valid

func ValidateTitle

func ValidateTitle(title string) error

ValidateTitle checks if title 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

func (c *Category) GetAncestorIDs() []string

GetAncestorIDs returns all ancestor category IDs from root to parent

func (*Category) GetDescendantIDs

func (c *Category) GetDescendantIDs() []string

GetDescendantIDs returns all descendant category IDs recursively

func (*Category) HasChildren

func (c *Category) HasChildren() bool

HasChildren returns true if this category has child categories

func (*Category) IsRoot

func (c *Category) IsRoot() bool

IsRoot returns true if this category has no parent

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

func NewProduct

func NewProduct(sku, title, body string, price float64, currency, categoryID string) (*Product, error)

NewProduct creates a new product with generated ID and timestamps

func (*Product) Validate

func (p *Product) Validate() error

Validate performs comprehensive validation on the product

Jump to

Keyboard shortcuts

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