Documentation
¶
Index ¶
- type CreateProductInput
- type CreateProductVariantInput
- type Module
- func (m *Module) CreateProduct(ctx context.Context, input CreateProductInput) (*Product, error)
- func (m *Module) DeleteProduct(ctx context.Context, id string) (bool, error)
- func (m *Module) FieldResolvers() map[string]any
- func (m *Module) GetProduct(ctx context.Context, id string) (*Product, error)
- func (m *Module) ID() string
- func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error
- func (m *Module) ListProducts(ctx context.Context) ([]*Product, error)
- func (m *Module) Models() []any
- func (m *Module) Mutations() map[string]any
- func (m *Module) PersistProduct(ctx context.Context, input any) (any, error)
- func (m *Module) PersistProductStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) Queries() map[string]any
- func (m *Module) Repo() *Repository
- func (m *Module) Routes() []mdk.Route
- func (m *Module) Shutdown(ctx context.Context) error
- func (m *Module) UpdateProduct(ctx context.Context, id string, input UpdateProductInput) (*Product, error)
- func (m *Module) UpdateProductDetails(ctx context.Context, input any) (any, error)
- func (m *Module) UpdateProductDetailsStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) ValidateProduct(ctx context.Context, input any) (any, error)
- func (m *Module) ValidateProductStep(sCtx mdk.StepContext) mdk.StepResult
- type Product
- type ProductDetails
- type ProductDetailsInput
- type ProductImage
- type ProductImageInput
- type ProductOption
- type ProductOptionInput
- type ProductVariant
- type Repository
- func (r *Repository) Delete(ctx context.Context, id string) error
- func (r *Repository) GetByHandle(ctx context.Context, handle string) (*Product, error)
- func (r *Repository) GetByID(ctx context.Context, id string) (*Product, error)
- func (r *Repository) List(ctx context.Context) ([]*Product, error)
- func (r *Repository) Save(ctx context.Context, p *Product) error
- type SEOInput
- type StringList
- type UpdateProductInput
- type VariantOption
- type VariantOptionInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateProductInput ¶
type CreateProductInput struct {
ID string `json:"id"`
Name string `json:"name"`
Handle string `json:"handle"`
Description *string `json:"description,omitempty"`
Type *string `json:"type,omitempty"`
Status *string `json:"status,omitempty"`
Details *ProductDetailsInput `json:"details,omitempty"`
SEO *SEOInput `json:"seo,omitempty"`
Metadata mdk.Metadata `json:"metadata,omitempty"`
AISystemContext *string `json:"ai_system_context,omitempty"`
Options []ProductOptionInput `json:"options,omitempty"`
Variants []CreateProductVariantInput `json:"variants,omitempty"`
Images []ProductImageInput `json:"images,omitempty"`
}
type CreateProductVariantInput ¶
type CreateProductVariantInput struct {
Title string `json:"title"`
Price float64 `json:"price"`
CompareAtPrice *float64 `json:"compare_at_price,omitempty"`
Details *ProductDetailsInput `json:"details,omitempty"`
Options []VariantOptionInput `json:"options,omitempty"`
Metadata mdk.Metadata `json:"metadata,omitempty"`
}
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements the mdk.Module interface for the Product.
func (*Module) CreateProduct ¶
func (*Module) DeleteProduct ¶
func (*Module) FieldResolvers ¶
func (*Module) GetProduct ¶
func (*Module) ListProducts ¶
func (*Module) PersistProduct ¶
PersistProduct saves the product to the database.
func (*Module) PersistProductStep ¶
func (m *Module) PersistProductStep(sCtx mdk.StepContext) mdk.StepResult
PersistProductStep wraps PersistProduct to mdk.StepHandler.
func (*Module) Repo ¶
func (m *Module) Repo() *Repository
func (*Module) UpdateProduct ¶
func (*Module) UpdateProductDetails ¶
UpdateProductDetails updates an existing product's information.
func (*Module) UpdateProductDetailsStep ¶
func (m *Module) UpdateProductDetailsStep(sCtx mdk.StepContext) mdk.StepResult
UpdateProductDetailsStep wraps UpdateProductDetails to mdk.StepHandler.
func (*Module) ValidateProduct ¶
ValidateProduct checks if the product data is valid.
func (*Module) ValidateProductStep ¶
func (m *Module) ValidateProductStep(sCtx mdk.StepContext) mdk.StepResult
ValidateProductStep wraps ValidateProduct to mdk.StepHandler.
type Product ¶
type Product struct {
ID string `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"`
Handle string `gorm:"uniqueIndex;not null" json:"handle"`
Description string `json:"description"`
Type string `gorm:"default:PHYSICAL" json:"type"` // PHYSICAL, DIGITAL, SERVICE
Status string `gorm:"default:DRAFT" json:"status"` // DRAFT, PUBLISHED, ARCHIVED
Details ProductDetails `gorm:"embedded;embeddedPrefix:details_" json:"details"`
SEO seo.SEO `gorm:"embedded;embeddedPrefix:seo_" json:"seo"`
Metadata mdk.Metadata `gorm:"type:text" json:"metadata"`
AISystemContext string `json:"ai_system_context"`
Options []ProductOption `gorm:"foreignKey:ProductID;constraint:OnDelete:CASCADE" json:"options"`
Variants []ProductVariant `gorm:"foreignKey:ProductID;constraint:OnDelete:CASCADE" json:"variants"`
Images []ProductImage `gorm:"foreignKey:ProductID;constraint:OnDelete:CASCADE" json:"images"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
Product represents the main catalog entity.
type ProductDetails ¶
type ProductDetails struct {
SKU *string `gorm:"column:sku" json:"sku,omitempty"`
Barcode *string `gorm:"column:barcode" json:"barcode,omitempty"`
HSNCode *string `gorm:"column:hsn_code" json:"hsn_code,omitempty"`
Weight *float64 `gorm:"column:weight" json:"weight,omitempty"`
Length *float64 `gorm:"column:length" json:"length,omitempty"`
Width *float64 `gorm:"column:width" json:"width,omitempty"`
Height *float64 `gorm:"column:height" json:"height,omitempty"`
FileUrl *string `gorm:"column:file_url" json:"file_url,omitempty"`
MaxDownloads *int `gorm:"column:max_downloads" json:"max_downloads,omitempty"`
DownloadExpirationHours *int `gorm:"column:download_expiration_hours" json:"download_expiration_hours,omitempty"`
}
ProductDetails groups package shipping specifications and digital download details.
type ProductDetailsInput ¶
type ProductDetailsInput struct {
SKU *string `json:"sku,omitempty"`
Barcode *string `json:"barcode,omitempty"`
HSNCode *string `json:"hsn_code,omitempty"`
Weight *float64 `json:"weight,omitempty"`
Length *float64 `json:"length,omitempty"`
Width *float64 `json:"width,omitempty"`
Height *float64 `json:"height,omitempty"`
FileUrl *string `json:"file_url,omitempty"`
MaxDownloads *int `json:"max_downloads,omitempty"`
DownloadExpirationHours *int `json:"download_expiration_hours,omitempty"`
}
type ProductImage ¶
type ProductImage struct {
ID string `gorm:"primaryKey" json:"id"`
ProductID string `gorm:"index;not null" json:"product_id"`
VariantID *string `gorm:"index" json:"variant_id,omitempty"`
URL string `gorm:"not null" json:"url"`
AltText string `json:"alt_text"`
SortOrder int `gorm:"default:0" json:"sort_order"`
}
ProductImage represents media links associated with the product or particular variants.
func (*ProductImage) BeforeCreate ¶
func (pi *ProductImage) BeforeCreate(tx *gorm.DB) error
type ProductImageInput ¶
type ProductOption ¶
type ProductOption struct {
ID string `gorm:"primaryKey" json:"id"`
ProductID string `gorm:"index;not null" json:"product_id"`
Name string `gorm:"not null" json:"name"`
Values StringList `gorm:"type:text" json:"values"`
}
ProductOption defines the option names (e.g., Color, Size) and allowed values for variations.
func (*ProductOption) BeforeCreate ¶
func (po *ProductOption) BeforeCreate(tx *gorm.DB) error
type ProductOptionInput ¶
type ProductVariant ¶
type ProductVariant struct {
ID string `gorm:"primaryKey" json:"id"`
ProductID string `gorm:"index;not null" json:"product_id"`
Title string `gorm:"not null" json:"title"`
Price float64 `gorm:"not null" json:"price"`
CompareAtPrice *float64 `json:"compare_at_price,omitempty"`
Details ProductDetails `gorm:"embedded;embeddedPrefix:details_" json:"details"`
Options []VariantOption `gorm:"foreignKey:VariantID;constraint:OnDelete:CASCADE" json:"options"`
Metadata mdk.Metadata `gorm:"type:text" json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
ProductVariant represents a stockable configuration of a product with its own price.
func (*ProductVariant) BeforeCreate ¶
func (pv *ProductVariant) BeforeCreate(tx *gorm.DB) error
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository handles database operations for products, variants, and catalog entities.
func NewRepository ¶
func NewRepository(database *gorm.DB) *Repository
NewRepository creates a new product repository.
func (*Repository) Delete ¶
func (r *Repository) Delete(ctx context.Context, id string) error
Delete removes a product from the database (cascade deletes options, variants, images).
func (*Repository) GetByHandle ¶
GetByHandle retrieves a product by its unique URL slug/handle, preloading all relationships.
func (*Repository) GetByID ¶
GetByID retrieves a product by its ID, preloading all options, variants, options per variant, and images.
type StringList ¶
type StringList []string
StringList represents a slice of strings serialized as JSON text in the database.
func (*StringList) Scan ¶
func (sl *StringList) Scan(val interface{}) error
Scan scans value into StringList.
type UpdateProductInput ¶
type UpdateProductInput struct {
Name *string `json:"name,omitempty"`
Handle *string `json:"handle,omitempty"`
Description *string `json:"description,omitempty"`
Type *string `json:"type,omitempty"`
Status *string `json:"status,omitempty"`
Details *ProductDetailsInput `json:"details,omitempty"`
SEO *SEOInput `json:"seo,omitempty"`
Metadata mdk.Metadata `json:"metadata,omitempty"`
AISystemContext *string `json:"ai_system_context,omitempty"`
}
type VariantOption ¶
type VariantOption struct {
ID string `gorm:"primaryKey" json:"id"`
VariantID string `gorm:"index;not null" json:"variant_id"`
Name string `gorm:"not null" json:"name"`
Value string `gorm:"not null" json:"value"`
}
VariantOption defines the key-value options chosen for a specific variant (e.g. Size: "XL").
func (*VariantOption) BeforeCreate ¶
func (vo *VariantOption) BeforeCreate(tx *gorm.DB) error