model

package
v0.0.0-...-e662f33 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AlphaNumerics      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	ErrProductNotFound = fmt.Errorf("product not found")
)
View Source
var (
	ErrNoRatings = errors.New("no ratings for product")
)
View Source
var (
	ErrStoreNotFound = errors.New("store not found")
)

Functions

func GetProductReviewSummary

func GetProductReviewSummary(db *gorm.DB, productId string) (*reviewSummary, error)

func NewProductId

func NewProductId(count ...int) string

Types

type Product

type Product struct {
	Id          string `gorm:"primaryKey"`
	StoreId     string
	Title       string
	Slug        string
	Description string
	// Category: should be written with hierarcy as 'Shoes->Sneakers'
	Category string
	// Tags: comma separated string, e.g. 'shoes,sneakers,running'
	Tags string
	// Price: in IDR; if product has variant, then this is the lowest price
	Price int64
	// Stock: if product has no variant, then this is the actual stock
	Stock         int64
	TotalViews    int64
	CreatedAt     int64                  `gorm:"autoCreateTime:milli"`
	UpdatedAt     int64                  `gorm:"autoUpdateTime:milli"`
	Variants      []*ProductVariantGroup `gorm:"-"`
	AverageRating float64                `gorm:"-"`
	TotalReview   int64                  `gorm:"-"`
	TotalSold     int64                  `gorm:"-"`
}

func GetAllProductsBySearch

func GetAllProductsBySearch(db *gorm.DB, search, category string, page, size int) ([]*Product, error)

func GetAllProductsByStore

func GetAllProductsByStore(db *gorm.DB, storeId string) ([]*Product, error)

func (*Product) Delete

func (p *Product) Delete(db *gorm.DB) error

func (*Product) FillVariants

func (p *Product) FillVariants(db *gorm.DB) error

func (*Product) GetById

func (p *Product) GetById(db *gorm.DB, id string) error

func (*Product) GetBySlug

func (p *Product) GetBySlug(db *gorm.DB, slug string) error

func (*Product) GetSlug

func (p *Product) GetSlug() string

func (*Product) Save

func (p *Product) Save(db *gorm.DB) error

type ProductReview

type ProductReview struct {
	Id        uint `gorm:"primaryKey"`
	ProductId string
	UserId    string
	Comment   string
	Rating    int
	CreatedAt int64                 `gorm:"autoCreateTime:milli"`
	Media     []*ProductReviewMedia `gorm:"foreignKey:ReviewId"`
}

func GetProductReviews

func GetProductReviews(db *gorm.DB, productId string) ([]*ProductReview, error)

type ProductReviewMedia

type ProductReviewMedia struct {
	Id       uint `gorm:"primaryKey"`
	ReviewId uint
	Url      string
}

type ProductVariant

type ProductVariant struct {
	Id        uint `gorm:"primaryKey"`
	ProductId string
	Name      string
	Value     string
	Price     int64
	Stock     int64
	CreatedAt int64 `gorm:"autoCreateTime:milli"`
	UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
}

ProductVariant represents data in db

func (*ProductVariant) Save

func (va *ProductVariant) Save(db *gorm.DB) error

type ProductVariantGroup

type ProductVariantGroup struct {
	// Name: Type or Title of variant, e.g. Color, Size, etc.
	Name string
	// Values: Array of actual values, e.g. [Red, Blue, Green] or [S, M, L]
	Values []*VariantItem
}

type Store

type Store struct {
	Id          string `gorm:"primaryKey"`
	Name        string
	Description string
	City        string
	Province    string
	UserId      string
	ImageFull   string
	ImageThumb  string
	IsPremium   bool
	IsOfficial  bool
	CreatedAt   int64 `gorm:"autoCreateTime:milli"`
	UpdatedAt   int64 `gorm:"autoUpdateTime:milli"`
}

func (*Store) FindById

func (s *Store) FindById(db *gorm.DB, id string) error

func (*Store) FindByUserId

func (s *Store) FindByUserId(db *gorm.DB, userId string) error

type VariantItem

type VariantItem struct {
	Value string
	Price int64
	Stock int64
}

Jump to

Keyboard shortcuts

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