Documentation
¶
Index ¶
- func SaveData(data interface{}) error
- func ValidateUniq(fl validator.FieldLevel) bool
- type Category
- type CategoryValidator
- type LoginValidator
- type Option
- type OptionParams
- type OptionsValidator
- type Product
- func (p *Product) AddOption(option Option) error
- func (p *Product) AddOptions(options []Option) error
- func (p *Product) AfterCreate(tx *gorm.DB) (err error)
- func (p *Product) DeleteOption(option *Option) error
- func (p *Product) FindOptionByID(id string) (*Option, error)
- func (p *Product) FindVariantByID(id string) (*Variant, error)
- func (p *Product) GetCategory() error
- func (p *Product) GetDefaultVariant() *Variant
- func (p *Product) GetTags() error
- func (p *Product) OptionExists(name string) bool
- func (p *Product) RebuildVariants()
- func (p *Product) RemoveTag(tagName string)
- func (p *Product) SetTag(tagName string) error
- func (p *Product) SoftDeleteVaiants()
- type ProductValidator
- type Tag
- type Tagging
- type User
- type UserValidator
- type Variant
- type VariantValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateUniq ¶
func ValidateUniq(fl validator.FieldLevel) bool
Types ¶
type Category ¶
func GetCategories ¶
func GetCategories() []Category
func GetCategoryByID ¶
func (*Category) SetDeletedAt ¶
type CategoryValidator ¶
type CategoryValidator struct {
CategoryTmp struct {
Name string `form:"name" json:"name" binding:"required,is-uniq"`
Slug string `form:"slug" json:"slug" binding:"required"`
} `json:"category"`
CategoryModel Category `json:"-"`
}
func (*CategoryValidator) TableName ¶
func (c *CategoryValidator) TableName() string
type LoginValidator ¶
type LoginValidator struct {
UserTmp struct {
Email string `form:"email" json:"email" binding:"required,email"`
Password string `form:"password" json:"password" binding:"required,min=6,max=64"`
} `json:"user"`
UserModel User `json:"-"`
}
LoginValidator ...
type Option ¶
type Option struct {
ID uint `gorm:"primary_key" json:"id" structs:"id"`
Name string
Position int
ProductID uint
Product Product
Vals []byte // Can't be values, coz MySQL keyword
CreatedAt time.Time
UpdatedAt time.Time
}
func (*Option) RemoveValue ¶
type OptionParams ¶
type OptionsValidator ¶
type OptionsValidator struct {
OptionsTmp []OptionParams `json:"options"`
Options []Option `json:"-"`
}
Options Validator
type Product ¶
type Product struct {
gorm.Model
Title string `json:"title"`
BodyHTML *string `json:"body_html"`
PublishedAt *time.Time `json:"published_at"`
Vendor *string `json:"vendor"`
Keywords *string `json:"keywords"`
Price float32 `json:"price" sql:"default:0.0"`
Slug string `json:"slug"`
StockQty int `json:"stock_qty" sql:"default:0"`
Status int `json:"status" sql:"default:0"`
HotSale bool `json:"hot_sale" sql:"default:false"`
NewArrival bool `json:"new_arrival"` // 不需要 default:true 否则会有 bug
CategoryID int `json:"category_id"`
Tags []Tag `gorm:"many2many:taggings;"`
Taggings []Tagging
Category Category
Cover *string
Variants []Variant
Options []Option
}
func GetProductByID ¶
func GetProducts ¶
func GetProducts() []Product
func (*Product) AddOptions ¶
AddOptions 初始化 Options, delete 所有 variants!
func (*Product) AfterCreate ¶
AfterCreate 默认创建一个没有任何 option 的 Variant
func (*Product) DeleteOption ¶
DeleteOption 删除一个 Option
func (*Product) GetCategory ¶
func (*Product) GetDefaultVariant ¶
func (*Product) OptionExists ¶
OptionExists 是否存在 Name: name 的 Option
func (*Product) RebuildVariants ¶
func (p *Product) RebuildVariants()
RebuildVariants 根据 Options 生成相应的 Variants, 原有 Variants 删除???
func (*Product) SoftDeleteVaiants ¶
func (p *Product) SoftDeleteVaiants()
SoftDeleteVaiants 把关联的 Variants 也 delete
type ProductValidator ¶
type ProductValidator struct {
ProductTmp struct {
Title string `form:"title" json:"title" binding:"required"`
BodyHTML *string `form:"body_html" json:"body_html"`
PublishedAt *time.Time `form:"published_at" json:"published_at"`
Vendor *string `form:"vendor" json:"vendor"`
Keywords *string `form:"keywords" json:"keywords"`
Price float32 `form:"price" json:"price"`
Slug string `form:"slug" json:"slug" binding:"required"`
StockQty int `form:"stock_qty" json:"stock_qty"`
Status int `form:"status" json:"status"`
HotSale bool `form:"hot_sale" json:"hot_sale"`
NewArrival bool `form:"new_arrival" json:"new_arrival"`
CategoryID int `form:"category_id" json:"category_id"`
} `json:"product"`
ProductModel Product `json:"-"`
}
type UserValidator ¶
type UserValidator struct {
UserTmp struct {
Username string `json:"username" binding:"required"`
Email string `json:"email" binding:"required,email,is-uniq"`
Password string `json:"password" binding:"required,min=6,max=64"`
} `json:"user"`
UserModel User `json:"-"`
}
UserValidator ...
func (*UserValidator) TableName ¶
func (c *UserValidator) TableName() string
type Variant ¶
type Variant struct {
gorm.Model
Price float32
Sku string
Stock int
Position int
ProductID uint
Product Product
IsDefault bool
Option1 string
Option2 string
Option3 string
}
func VariantsBuilding ¶
type VariantValidator ¶
Click to show internal directories.
Click to hide internal directories.