model

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IMAGE_DISK_LOCAL = iota
	IMAGE_DISK_SEED
)

Disks

View Source
const (
	IMAGE_TYPE_PRODUCT = iota
	IMAGE_TYPE_PRODUCT_MAIN
)

Types

View Source
const (
	USER_TYPE_CLIENT = iota
	USER_TYPE_ADMIN
)

User type constant

Variables

This section is empty.

Functions

func JoinCategories

func JoinCategories(id int) func(*gorm.DB) *gorm.DB

func SetPivots

func SetPivots(db *gorm.DB)

Types

type AccessToken

type AccessToken struct {
	UUID      string `gorm:"primarykey;"`
	Token     string `gorm:"not null"`
	UserID    uint   `gorm:"foreignKey;"`
	UserAgent string `gorm:"not null"`
}

func (*AccessToken) String

func (a *AccessToken) String() string

type Category

type Category struct {
	gorm.Model
	Name     string `gorm:"size:128;unique;"`
	Status   bool   `gorm:"default:1;"`
	ParentID *uint
	Parent   *Category
	Children []Category `gorm:"foreignKey:ParentID"`
	Products []Product
}

Category model

type Configuration

type Configuration struct {
	ID uint `gorm:"primarykey;"`

	CreatedAt time.Time
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

type Coupon

type Coupon struct {
	gorm.Model
	Discount     float64 `gorm:"not null;"`
	Type         uint8   `gorm:"not null;"`
	Status       bool    `gorm:"not null;"`
	UserID       uint    `gorm:"foreignKey;"`
	ExpiracyDate time.Time
}

type Delivery

type Delivery struct {
	ID        uint    `gorm:"primaryKey"`
	Zone      string  `gorm:"not null;"`
	Price     float64 `gorm:"not null;"`
	Address   string  `gorm:"not null;"`
	InvoiceID uint    `gorm:"foreignKey;not null;"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Image

type Image struct {
	ID            uint   `gorm:"primarykey;"`
	BasePath      string `gorm:"-"`
	Path          string `gorm:"not null;"`
	Type          uint
	Disk          uint   `gorm:"not null;type:smallint"`
	ImageableType string `gorm:"not null;"`
	ImageableID   uint   `gorm:"not null;"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

func (*Image) AfterFind

func (i *Image) AfterFind(tx *gorm.DB) (err error)

type Invoice

type Invoice struct {
	ID        uint    `gorm:"primarykey;"`
	UserID    uint    `gorm:"foreingKey;not null;"`
	Subtotal  float64 `gorm:"not null;"`
	IVA       float64 `gorm:"not null;"`
	Total     float64 `gorm:"not null;"`
	Type      uint8   `gorm:"not null;"`
	Status    uint8   `gorm:"not null;"`
	Items     []InvoiceItem
	Payments  []Payment
	User      *User
	CreatedAt time.Time
	UpdatedAt time.Time
}

type InvoiceItem

type InvoiceItem struct {
	ID          uint    `gorm:"primarykey;"`
	Name        string  `gorm:"size:128;not null;"`
	Description string  `gorm:"not null;"`
	Price       float64 `gorm:"not null;"`
	InvoiceID   uint    `gorm:"foreingKey;not null;"`
	Invoice     *Invoice
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type Payment

type Payment struct {
	ID        uint    `gorm:"primarykey;"`
	Type      uint8   `gorm:"not null;"`
	Amount    float64 `gorm:"not null;"`
	Reference string
	InvoiceID uint `gorm:"foreingKey;not null;"`
	Invoice   *Invoice
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Product

type Product struct {
	gorm.Model
	Name        string `gorm:"size:128;unique;not null;"`
	Description string
	Price       float64 `gorm:"not null;"`
	Stock       uint
	CategoryID  uint
	Category    *Category
	Images      []Image `gorm:"polymorphic:Imageable;"`
}

Product model

type Profile

type Profile struct {
	UserID    uint `gorm:"foreingKey;not null;"`
	User      *User
	Name      string `gorm:"size:64;not null;" json:"name" validate:"required,max=64"`
	Lastname  string `gorm:"size:64;not null;" json:"lastname" validate:"required,max=64"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type ShoppingCart

type ShoppingCart struct {
	ID        uint  `gorm:"primaryKey"`
	Status    uint8 `gorm:"default:1;"`
	UserID    uint  `gorm:"foreingKey;not null;"`
	User      *User
	Products  []Product `gorm:"many2many:user_languages;"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type ShoppingCartProduct

type ShoppingCartProduct struct {
	ShoppingCartID uint `gorm:"primaryKey;"`
	ProductID      int  `gorm:"primaryKey;"`
	Quantity       uint `gorm:"not null;"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type User

type User struct {
	gorm.Model
	Email    string  `gorm:"size:64;unique;not null;" validate:"required,email,db_unique=users,max=64"`
	Password string  `gorm:"size:64;not null;" validate:"required,min=6,max=64"`
	Status   bool    `gorm:"default:1;not null;"`
	Type     int     `gorm:"default:0;size:1;not null;"`
	Profile  Profile `gorm:"constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	// Image    *Image  //`gorm:"polymorphic:Imageable;"`
	// Invoices Invoice
	Tokens []AccessToken
}

User model

func (*User) CreateAccressToken

func (u *User) CreateAccressToken(db *gorm.DB, userAgent string) (string, error)

CreateAccressToken creates and store a new access token for the calling user

func (*User) Register added in v0.0.2

func (u *User) Register(ctx context.Context, db *gorm.DB, authenticate bool) (string, error)

Register stores a new user in the database. If `authenticate` is true, an authentication token will be created

func (*User) Save added in v0.0.2

func (u *User) Save(db *gorm.DB) error

Save stores the user in the database, if the user already has a primary key, it will be updated

type Zone

type Zone struct {
	gorm.Model
	Name  string  `gorm:"not null;"`
	Price float64 `gorm:"not null;"`
}

Jump to

Keyboard shortcuts

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