models

package
v0.0.0-...-a38e679 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddItem

func AddItem(name, url string, rank int) error

func CreateUser

func CreateUser(newUser *UserModel) error

func DeleteItem

func DeleteItem(item *ItemModel) error

func GetAllItems

func GetAllItems() (*[]ItemModel, error)

func GetItems

func GetItems(condition interface{}, scopes ...func(*gorm.DB) *gorm.DB) (*[]ItemModel, error)

func GetReservedItems

func GetReservedItems(userID int) (*[]ItemModel, error)

func GetWantedItems

func GetWantedItems() (*[]ItemModel, error)

func ItemDefaultScope

func ItemDefaultScope(db *gorm.DB) *gorm.DB

func ItemOrderScope

func ItemOrderScope(db *gorm.DB) *gorm.DB

func ItemReserveScope

func ItemReserveScope(db *gorm.DB) *gorm.DB

func UpdateItemWithMap

func UpdateItemWithMap(item *ItemModel, updates map[string]interface{}) error

func UpdateUser

func UpdateUser(user *UserModel, updates UserModel) error

func UpdateUserWithMap

func UpdateUserWithMap(user *UserModel, updates map[string]interface{}) error

UpdateUserWithMap will update an existing user. A map is needed instead of the UserModel when you want/need to insert NULL sql field values.

func UserAuthScope

func UserAuthScope(db *gorm.DB) *gorm.DB

func UserDefaultScope

func UserDefaultScope(db *gorm.DB) *gorm.DB

func UserPassResetScope

func UserPassResetScope(db *gorm.DB) *gorm.DB

Types

type DefaultModel

type DefaultModel struct {
	ID        int       `gorm:"column:id;type:integer;primary_key;unique;AUTO_INCREMENT"`
	CreatedAt time.Time `gorm:"column:createdAt;type:DATETIME;not null"`
	UpdatedAt time.Time `gorm:"column:updatedAt;type:DATETIME;not null"`
}

type ItemModel

type ItemModel struct {
	DefaultModel
	Name       string    `gorm:"column:name;type:varchar(255);not null"`
	URL        string    `gorm:"column:url;type:varchar(255);not null"`
	Reserved   bool      `gorm:"column:reserved;type:tinyint(1);not null;DEFAULT:false"`
	Reserver   UserModel `gorm:"foreignkey:ReserverID"`
	ReserverID *int      `gorm:"column:reserverid;type:integer;DEFAULT:NULL"`
	Rank       int       `gorm:"colunm:rank;type:integer;DEFAULT:NULL"`
}

func FindOneItem

func FindOneItem(condition interface{}, scopes ...func(*gorm.DB) *gorm.DB) (*ItemModel, error)

func (ItemModel) TableName

func (ItemModel) TableName() string

type UserModel

type UserModel struct {
	DefaultModel
	Username             string      `gorm:"column:username;type:varchar(255);unique;not null"`
	PasswordHash         string      `gorm:"column:hash;type:varchar(255);not null"`
	PasswordReset        bool        `gorm:"column:passwordreset;type:tinyint(1);not null;DEFAULT:false"`
	PasswordResetToken   *string     `gorm:"column:passwordResetToken;type:varchar(255);DEFAULT:NULL"`
	PasswordResetExpires *time.Time  `gorm:"column:passwordResetExpires;type:DATETIME;DEFAULT:NULL"`
	UserLevel            uint        `gorm:"column:userlevel;type:tinyint unsigned;not null"`
	EMail                string      `gorm:"column:email;type:varchar(255);not null"`
	FirstName            string      `gorm:"column:firstname;type:varchar(255);not null"`
	LastName             string      `gorm:"column:lastname;type:varchar(255);not null"`
	ReservedItems        []ItemModel `gorm:"foreignkey:ReserverID"`
}

UserModel is the db structure for users

func FindOneUser

func FindOneUser(condition interface{}, scopes ...func(*gorm.DB) *gorm.DB) (*UserModel, error)

FindOneUser will search for a user that matches the supplied condition. Will mask Record Not Found Errors.

func (*UserModel) SetPassword

func (u *UserModel) SetPassword(password string) error

func (UserModel) TableName

func (UserModel) TableName() string

func (*UserModel) ValidatePassword

func (u *UserModel) ValidatePassword(password string) bool

Jump to

Keyboard shortcuts

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