models

package
v0.0.0-...-f0220a8 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brand

type Brand struct {
	gorm.Model
	Name        string    `gorm:"size:100;not null" json:"name"`
	Description string    `gorm:"type:text" json:"description"`
	Discount    float64   `gorm:"type:decimal(10,2)" json:"discount"`
	Products    []Product `gorm:"foreignKey:BrandID"`
}

type Order

type Order struct {
	gorm.Model
	UserID        uint           `gorm:"not null" json:"user_id"`
	User          User           `json:"user"`
	OrderProducts []OrderProduct `gorm:"foreignKey:OrderID" json:"order_products"`
	Total         float64        `gorm:"type:decimal(10,2);not null" json:"total"`
}

type OrderProduct

type OrderProduct struct {
	ID        uint    `gorm:"primaryKey" json:"id"`
	OrderID   uint    `gorm:"not null" json:"order_id"`
	ProductID uint    `gorm:"not null" json:"product_id"`
	Quantity  uint    `gorm:"not null" json:"quantity"`
	Price     float64 `gorm:"type:decimal(10,2);not null" json:"price"`
	Order     Order   `gorm:"foreignKey:OrderID" json:"order"`
	Product   Product `gorm:"foreignKey:ProductID" json:"product"`
}

type Product

type Product struct {
	gorm.Model
	Name          string         `gorm:"size:100;not null" json:"name"`
	Description   string         `gorm:"type:text" json:"description"`
	Price         float64        `gorm:"type:decimal(10,2);not null" json:"price"`
	Discount      float64        `gorm:"type:decimal(10,2)" json:"discount"`
	Stock         uint           `gorm:"not null" json:"stock"`
	BrandID       uint           `json:"brand_id"`
	Brand         Brand          `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"brand"`
	OrderProducts []OrderProduct `gorm:"foreignKey:ProductID" json:"order_products"`
}

type Role

type Role string
const (
	RoleAdmin  Role = "admin"
	RoleClient Role = "client"
)

type User

type User struct {
	gorm.Model
	Name              string  `gorm:"size:100;not null" json:"name"`
	Email             string  `gorm:"size:100;not null;unique" json:"email"`
	Password          string  `gorm:"size:255;not null" json:"-"`
	Role              Role    `gorm:"size:100;not null" json:"role"`
	GoogleID          *string `gorm:"size:255;unique" json:"google_id,omitempty"`
	ProfilePictureURL *string `gorm:"size:255" json:"profile_picture_url"`
	BillingAddress    *string `gorm:"type:text" json:"billing_address"`
	StripeCustomerID  *string `gorm:"size:255" json:"stripe_customer_id"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

func (*User) IsValidRole

func (u *User) IsValidRole() bool

Jump to

Keyboard shortcuts

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