product

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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 NewModule

func NewModule() *Module

func (*Module) CreateProduct

func (m *Module) CreateProduct(ctx context.Context, input CreateProductInput) (*Product, error)

func (*Module) DeleteProduct

func (m *Module) DeleteProduct(ctx context.Context, id string) (bool, error)

func (*Module) FieldResolvers

func (m *Module) FieldResolvers() map[string]any

func (*Module) GetProduct

func (m *Module) GetProduct(ctx context.Context, id string) (*Product, error)

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error

func (*Module) ListProducts

func (m *Module) ListProducts(ctx context.Context) ([]*Product, error)

func (*Module) Models

func (m *Module) Models() []any

func (*Module) Mutations

func (m *Module) Mutations() map[string]any

func (*Module) PersistProduct

func (m *Module) PersistProduct(ctx context.Context, input any) (any, error)

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) Queries

func (m *Module) Queries() map[string]any

func (*Module) Repo

func (m *Module) Repo() *Repository

func (*Module) Routes

func (m *Module) Routes() []mdk.Route

func (*Module) Shutdown

func (m *Module) Shutdown(ctx context.Context) error

func (*Module) UpdateProduct

func (m *Module) UpdateProduct(ctx context.Context, id string, input UpdateProductInput) (*Product, error)

func (*Module) UpdateProductDetails

func (m *Module) UpdateProductDetails(ctx context.Context, input any) (any, error)

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

func (m *Module) ValidateProduct(ctx context.Context, input any) (any, error)

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.

func (*Product) BeforeCreate

func (p *Product) BeforeCreate(tx *gorm.DB) error

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 ProductImageInput struct {
	VariantID *string `json:"variant_id,omitempty"`
	URL       string  `json:"url"`
	AltText   *string `json:"alt_text,omitempty"`
	SortOrder *int    `json:"sort_order,omitempty"`
}

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 ProductOptionInput struct {
	Name   string   `json:"name"`
	Values []string `json:"values"`
}

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

func (r *Repository) GetByHandle(ctx context.Context, handle string) (*Product, error)

GetByHandle retrieves a product by its unique URL slug/handle, preloading all relationships.

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, id string) (*Product, error)

GetByID retrieves a product by its ID, preloading all options, variants, options per variant, and images.

func (*Repository) List

func (r *Repository) List(ctx context.Context) ([]*Product, error)

List retrieves all products with all of their relationships preloaded.

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, p *Product) error

Save persists a product and all of its nested relationships (options, variants, images).

type SEOInput

type SEOInput struct {
	MetaTitle       *string `json:"metaTitle,omitempty"`
	MetaDescription *string `json:"metaDescription,omitempty"`
	MetaKeywords    *string `json:"metaKeywords,omitempty"`
	MetaImage       *string `json:"metaImage,omitempty"`
}

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.

func (StringList) Value

func (sl StringList) Value() (driver.Value, error)

Value returns the driver Value.

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

type VariantOptionInput

type VariantOptionInput struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Jump to

Keyboard shortcuts

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