models

package
v0.0.0-...-feb40e3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ADMIN = "admin"

ADMIN is an admin role name

View Source
const ANONYMOUS = "anonymous"

ANONYMOUS is an anonymous role name

View Source
const CUSTOMER = "customer"

CUSTOMER is a customer role name

View Source
const MANAGER = "manager"

MANAGER is a manager role name

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate()

AutoMigrate runs gorm auto migration

func GetDB

func GetDB() *gorm.DB

GetDB returns database handler

func GetSetting

func GetSetting(code string) string

GetSetting returns a site setting by its code, empty string otherwise

func SeedDB

func SeedDB()

SeedDB seeds database with initial DEMO data, don't leave default admin password for production

func SetDB

func SetDB(connection string)

SetDB establishes connection to database and saves its handler into db *gorm.DB

Types

type Category

type Category struct {
	Model

	Title           string  `form:"title"`
	Slug            string  `form:"slug"`
	Excerpt         string  `form:"excerpt"`
	Description     string  `form:"description"`
	MetaKeywords    string  `form:"meta_keywords"`
	MetaDescription string  `form:"meta_description"`
	Published       bool    `form:"published"`
	ParentID        *uint64 `form:"parent_id"`
	Products        []Product
	Class           string     `form:"class"`
	Ord             int        `form:"ord"`
	Children        []Category `gorm:"foreignkey:ParentID"`
}

Category type contains product category info

func (*Category) BeforeSave

func (c *Category) BeforeSave() (err error)

BeforeSave gorm hook

func (*Category) GetParent

func (c *Category) GetParent() Category

GetParent returns parent item

func (*Category) IDs

func (c *Category) IDs() []uint64

IDs returns a slice of category id and ids of its children

func (*Category) URL

func (c *Category) URL() string

URL returns category url

type Error

type Error struct {
	Error string `json:"error"`
}

Error type contains JSON error info

type Image

type Image struct {
	Model

	URL       string  `form:"url"`
	ProductID uint64  `form:"product_id"`
	Hash      string  `gorm:"-" form:"-"`
	Product   Product `gorm:"save_associations:false" binding:"-" form:"-"`
}

Image type contains image info

type Login

type Login struct {
	Email    string `form:"email" binding:"required"`
	Password string `form:"password" binding:"required"`
}

Login view model

type Manage

type Manage struct {
	FirstName       string `form:"first_name" binding:"required"`
	MiddleName      string `form:"middle_name" binding:"required"`
	LastName        string `form:"last_name" binding:"required"`
	Email           string `binding:"-"`
	Password        string `form:"password" binding:"required"`
	PasswordConfirm string `form:"password_confirm" binding:"required"`
}

Manage user view model

type Menu struct {
	Model

	Code  string `form:"code" binding:"required"`
	Title string `form:"title" binding:"required"`
	Items []MenuItem
}

Menu type contains menu info

type MenuItem struct {
	Model

	Title    string     `form:"title" binding:"required"`
	URL      string     `form:"url"`
	Ord      int        `form:"ord"`
	ParentID *uint64    `form:"parent_id"`
	Class    string     `form:"class"`
	MenuID   uint64     `form:"menu_id" binding:"required"`
	Children []MenuItem `gorm:"foreignkey:ParentID"`
}

MenuItem type contains menu item info

func (m *MenuItem) GetParent() MenuItem

GetParent returns parent item

type Model

type Model struct {
	ID        uint64     `form:"id" gorm:"primary_key"`
	CreatedAt time.Time  `binding:"-" form:"-"`
	UpdatedAt time.Time  `binding:"-" form:"-"`
	DeletedAt *time.Time `binding:"-" form:"-"`
}

Model is a tuned version of gorm.Model

type Order

type Order struct {
	Model

	FirstName  string    `form:"first_name"`
	MiddleName string    `form:"middle_name"`
	LastName   string    `form:"last_name"`
	Email      string    `form:"email"`
	Phone      string    `form:"phone"`
	Comment    string    `form:"comment"`
	Products   []Product `gorm:"many2many:order_products;save_associations:false" binding:"-" form:"-"`
}

Order type contains buy order info

func (*Order) BeforeCreate

func (o *Order) BeforeCreate() (err error)

BeforeCreate gorm hook

type OrderConsult

type OrderConsult struct {
	Name  string `form:"order_name"`
	Phone string `form:"order_phone"`
}

OrderConsult type contains consult order info

type Page

type Page struct {
	Model

	Title           string `form:"title"`
	Description     string `form:"description"`
	Slug            string `form:"slug"`
	Published       bool   `form:"published"`
	MetaKeywords    string `form:"meta_keywords"`
	MetaDescription string `form:"meta_description"`
}

Page type contains page info

func (*Page) BeforeSave

func (p *Page) BeforeSave() (err error)

BeforeSave gorm hook

func (*Page) URL

func (p *Page) URL() string

URL returns article url

type Product

type Product struct {
	Model

	Title           string   `form:"title"`
	Description     string   `form:"description"`
	MetaKeywords    string   `form:"meta_keywords"`
	MetaDescription string   `form:"meta_description"`
	CategoryID      uint64   `form:"category_id"`
	Published       bool     `form:"published"`
	Slug            string   `form:"slug"`
	Category        Category `gorm:"save_associations:false" binding:"-" form:"-"`
	ImageIds        []uint64 `form:"imageids" gorm:"-"` //hack
	DefaultImageID  uint64   `form:"defaultimageid"`
	Recommended     bool     `form:"recommended"`
	Images          []Image
	Orders          []Order `gorm:"save_associations:false" binding:"-" form:"-"`
}

Product type contains product info

func (*Product) BeforeSave

func (p *Product) BeforeSave() (err error)

BeforeSave gorm hook

func (*Product) DefaultImage

func (p *Product) DefaultImage() string

DefaultImage returns url of the default product img

func (*Product) URL

func (p *Product) URL() string

URL returns product url

type Register

type Register struct {
	FirstName       string `form:"first_name" binding:"required"`
	MiddleName      string `form:"middle_name" binding:"required"`
	LastName        string `form:"last_name" binding:"required"`
	Email           string `form:"email" binding:"required"`
	Password        string `form:"password" binding:"required"`
	PasswordConfirm string `form:"password_confirm" binding:"required"`
}

Register view model

type Setting

type Setting struct {
	Model

	Code  string `binding:"required" form:"code"`
	Title string `form:"title"`
	Value string `form:"value"`
}

Setting type contains settings info

type Slide

type Slide struct {
	Model

	Title         string `form:"title" binding:"required"`
	Content       string `form:"content"`
	NavigationURL string `form:"navigation_url"`
	FileURL       string `form:"file_url"`
	Ord           int    `form:"ord"`
}

Slide type contains carousel slide info

type User

type User struct {
	Model

	Email      string `form:"email" binding:"required"`
	FirstName  string `form:"first_name"`
	MiddleName string `form:"middle_name"`
	LastName   string `form:"last_name"`
	Password   string `form:"password" binding:"required"`
	Role       string `form:"role" binding:"required"`
}

User type contains user info

func (*User) BeforeSave

func (u *User) BeforeSave() (err error)

BeforeSave gorm hook

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin checks if user is admin

func (*User) IsCustomer

func (u *User) IsCustomer() bool

IsCustomer checks if user is a customer

func (*User) IsManager

func (u *User) IsManager() bool

IsManager checks if user is a manager

Jump to

Keyboard shortcuts

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