model

package
v0.0.0-...-9de6353 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaxPercent = 10
)

Variables

This section is empty.

Functions

func GetTaxAmount

func GetTaxAmount(price float64) float64

func GetTaxPercent

func GetTaxPercent() float64

Types

type Address

type Address struct {
	ID         string `gorm:"primaryKey;not null"`
	User       User
	UserID     string `gorm:"type:varchar(255);not null;unique;index"`
	Name       string `gorm:"type:varchar(255);not null"`
	IsPrimary  bool
	CityID     string `gorm:"type:varchar(255);not null"`
	ProvinceID string `gorm:"type:varchar(255);not null"`
	Address1   string `gorm:"type:varchar(255);not null"`
	Address2   string `gorm:"type:varchar(255);not null"`
	Phone      string `gorm:"type:varchar(255);not null"`
	Email      string `gorm:"type:varchar(255);not null"`
	PostCode   string `gorm:"type:varchar(255);not null"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

type Cart

type Cart struct {
	ID              string `gorm:"primaryKey;not null;unique"`
	CartItems       []CartItem
	BaseTotalPrice  decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxAmount       decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxPercent      decimal.Decimal `gorm:"type:decimal(10,2)"`
	DiscountAmount  decimal.Decimal `gorm:"type:decimal(16,2)"`
	DiscountPercent decimal.Decimal `gorm:"type:decimal(10,2)"`
	GrandTotal      decimal.Decimal `gorm:"type:decimal(16,2)"`
}

func (*Cart) AddItem

func (c *Cart) AddItem(db *gorm.DB, item CartItem) (*CartItem, error)

func (*Cart) CalculateCart

func (c *Cart) CalculateCart(db *gorm.DB, cartID string) (*Cart, error)

func (*Cart) CreateCart

func (c *Cart) CreateCart(db *gorm.DB, cartID string) (*Cart, error)

func (*Cart) GetCart

func (c *Cart) GetCart(db *gorm.DB, cartID string) (*Cart, error)

func (*Cart) GetItems

func (c *Cart) GetItems(db *gorm.DB, cartID string) ([]CartItem, error)

func (*Cart) RemoveItemByID

func (c *Cart) RemoveItemByID(db *gorm.DB, itemID string) error

func (*Cart) UpdateItemQty

func (c *Cart) UpdateItemQty(db *gorm.DB, itemID string, qty int) (*CartItem, error)

type CartItem

type CartItem struct {
	ID              string `gorm:"primaryKey;not null;unique"`
	Cart            Cart
	CartID          string `gorm:"index;not null"`
	Product         Product
	ProductID       string `gorm:"index;not null"`
	Qty             int
	BasePrice       decimal.Decimal `gorm:"type:decimal(16,2)"`
	BaseTotal       decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxAmount       decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxPercent      decimal.Decimal `gorm:"type:decimal(10,2)"`
	DiscountAmount  decimal.Decimal `gorm:"type:decimal(16,2)"`
	DiscountPercent decimal.Decimal `gorm:"type:decimal(10,2)"`
	SubTotal        decimal.Decimal `gorm:"type:decimal(16,2)"`
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

func (*CartItem) BeforeCreate

func (c *CartItem) BeforeCreate(tx *gorm.DB) error

type Category

type Category struct {
	ID       string `gorm:"primaryKey;unique;not null"`
	ParentID string `gorm:"index"`

	Name      string `gorm:"type:varchar(255);unique;not null"`
	Slug      string `gorm:"type:varchar(255);unique;not null"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*Category) BeforeCreate

func (entity *Category) BeforeCreate(db *gorm.DB) error

func (*Category) BeforeUpdate

func (entity *Category) BeforeUpdate(db *gorm.DB) error

type Model

type Model struct {
	Model interface{}
}

func RegisterModels

func RegisterModels() []Model

type Order

type Order struct {
	ID                  string `gorm:"primaryKey;not null;unique"`
	UserID              string `gorm:"index;not null"`
	User                User
	OrderItems          []OrderItem
	OrderCustomer       *OrderCustomer
	Code                string `gorm:"type:varchar(50);index"`
	Status              int
	OrderDate           time.Time
	PaymentDue          time.Time
	PaymentStatus       string          `gorm:"type:varchar(50);index;not null"`
	PaymentToken        string          `gorm:"type:varchar(100);index"`
	BaseTotalPrice      decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxAmount           decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxPercent          decimal.Decimal `gorm:"type:decimal(10,2)"`
	DiscountAmount      decimal.Decimal `gorm:"type:decimal(16,2)"`
	DiscountPercent     decimal.Decimal `gorm:"type:decimal(10,2)"`
	ShippingCost        decimal.Decimal `gorm:"type:decimal(16,2)"`
	GrandTotal          decimal.Decimal `gorm:"type:decimal(16,2)"`
	Note                string          `gorm:"type:text"`
	ShippingCourier     string          `gorm:"type:varchar(100);not null"`
	ShippingServiceName string          `gorm:"type:varchar(100);not null"`
	ApprovedBy          string          `gorm:"size:36"`
	ApprovedAt          time.Time
	CancelledBy         string `gorm:"size:36"`
	CancelledAt         time.Time
	CancellationNote    string `gorm:"size:255"`
	CreatedAt           time.Time
	UpdatedAt           time.Time
	DeletedAt           gorm.DeletedAt
}

type OrderCustomer

type OrderCustomer struct {
	ID         string `gorm:"primaryKey;not null;unique"`
	User       User
	UserID     string `gorm:"index;not null"`
	Order      Order
	OrderID    string `gorm:"index;not null"`
	FirstName  string `gorm:"type:varchar(100);not null"`
	LastName   string `gorm:"type:varchar(100);not null"`
	CityID     string `gorm:"type:varchar(100);"`
	ProvinceID string `gorm:"type:varchar(100);"`
	Address1   string `gorm:"type:varchar(100);"`
	Address2   string `gorm:"type:varchar(100);"`
	Phone      string `gorm:"type:varchar(50);"`
	Email      string `gorm:"type:varchar(100);"`
	PostCode   string `gorm:"type:varchar(100);"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

type OrderItem

type OrderItem struct {
	ID              string `gorm:"primaryKey;not null;unique"`
	Order           Order
	OrderID         string `gorm:"index;not null"`
	Product         Product
	ProductID       string `gorm:"index;not null"`
	Qty             int
	BasePrice       decimal.Decimal `gorm:"type:decimal(16,2)"`
	BaseTotal       decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxAmount       decimal.Decimal `gorm:"type:decimal(16,2)"`
	TaxPercent      decimal.Decimal `gorm:"type:decimal(10,2)"`
	DiscountAmount  decimal.Decimal `gorm:"type:decimal(16,2)"`
	DiscountPercent decimal.Decimal `gorm:"type:decimal(10,2)"`
	SubTotal        decimal.Decimal `gorm:"type:decimal(16,2)"`
	Sku             string          `gorm:"size:36;index"`
	Name            string          `gorm:"size:255"`
	Weight          decimal.Decimal `gorm:"type:decimal(10,2)"`
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

type Payment

type Payment struct {
	ID          string `gorm:"primaryKey;not null;unique"`
	Order       Order
	OrderID     string          `gorm:"index;not null"`
	Number      string          `gorm:"type:varchar(100);index"`
	Amount      decimal.Decimal `gorm:"type:decimal(16,2)"`
	Method      string          `gorm:"type:varchar(100)"`
	Status      string          `gorm:"type:varchar(100)"`
	Token       string          `gorm:"type:varchar(100);index"`
	Payload     string          `gorm:"type:text"`
	PaymentType string          `gorm:"type:varchar(100)"`
	VaNumber    string          `gorm:"type:varchar(100)"`
	BillCode    string          `gorm:"type:varchar(100)"`
	BillKey     string          `gorm:"type:varchar(100)"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
	DeletedAt   gorm.DeletedAt
}

type Product

type Product struct {
	ID       string `gorm:"primaryKey;not null;unique"`
	ParentID string `gorm:"index"`
	User     User
	UserID   string `gorm:"index;not null"`

	Sku              string          `gorm:"type:varchar(100);index"`
	Name             string          `gorm:"type:varchar(255);not null"`
	Slug             string          `gorm:"type:varchar(255);not null"`
	Price            decimal.Decimal `gorm:"type:decimal(16,2);"`
	Stock            int
	Weight           decimal.Decimal `gorm:"type:decimal(10,2);"`
	ShortDescription string          `gorm:"type:text"`
	Description      string          `gorm:"type:text"`
	Status           int             `gorm:"default:0"`
	CreatedAt        time.Time
	UpdatedAt        time.Time
	DeletedAt        gorm.DeletedAt

	ProductImages []ProductImage
	Categories    []Category `gorm:"many2many:product_categories;"`
	CategoryID    []string   `json:"category_id" gorm:"-"`
}

func (*Product) BeforeCreate

func (entity *Product) BeforeCreate(db *gorm.DB) error

func (*Product) BeforeUpdate

func (entity *Product) BeforeUpdate(db *gorm.DB) error

func (*Product) FindByID

func (p *Product) FindByID(db *gorm.DB, productID string) (*Product, error)

func (*Product) FindBySlug

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

func (*Product) GetProducts

func (p *Product) GetProducts(db *gorm.DB, perPage int, page int) (*[]Product, int64, error)

type ProductCategories

type ProductCategories struct {
	ProductID  string `json:"product_id"`
	CategoryID string `json:"category_id"`
}

type ProductImage

type ProductImage struct {
	ID         string `gorm:"primaryKey;not null;unique"`
	Product    Product
	ProductID  string `gorm:"index;not null"`
	Path       string `gorm:"type:text"`
	ExtraLarge string `gorm:"type:text"`
	Large      string `gorm:"type:text"`
	Medium     string `gorm:"type:text"`
	Small      string `gorm:"type:text"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

type Shipment

type Shipment struct {
	ID          string `gorm:"primaryKey;not null;unique"`
	User        User
	UserID      string `gorm:"index;not null"`
	Order       Order
	OrderID     string `gorm:"index;not null"`
	TrackNumber string `gorm:"type:varchar(255);index"`
	Status      string `gorm:"type:varchar(36);index"`
}

type User

type User struct {
	ID            string `gorm:"primaryKey;not null"`
	Addresses     []Address
	FirstName     string    `gorm:"type:varchar(255);not null"`
	LastName      string    `gorm:"type:varchar(255);not null"`
	Email         string    `gorm:"type:varchar(255);unique;not null"`
	Password      string    `gorm:"type:varchar(255);not null" json:"-"`
	RememberToken string    `gorm:"type:varchar(255);not null" json:"-"`
	CreatedAt     time.Time `json:"-"`
	UpdatedAt     time.Time `json:"-"`
}

func (*User) BeforeCreate

func (entity *User) BeforeCreate(db *gorm.DB) error

func (*User) BeforeUpdate

func (entity *User) BeforeUpdate(db *gorm.DB) error

Jump to

Keyboard shortcuts

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