models

package
v0.0.0-...-786156a Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Models = []interface{}{
	&User{},
	&UserToken{},
	&LoginHistory{},
	&Article{},
	&Comment{},
	&ScoreHistory{},
	&PaymentHistory{},
	&CommentArchive{},
	&Admin{},
}

Functions

func GeneratePassword

func GeneratePassword(userPassword string) ([]byte, error)

GeneratePassword will generate a hashed password for us based on the user's input.

func ValidatePassword

func ValidatePassword(userPassword string, hashed []byte) (bool, error)

ValidatePassword will check if passwords are matched.

Types

type Admin

type Admin struct {
	ID              int64  `json:"id" form:"id"`
	Name            string `json:"name" form:"name"`
	Email           string
	Avatar          string `json:"avatar" form:"avatar"`
	EmailVerifiedAt time.Time
	Password        string
	RememberToken   string
	CreatedAt       time.Time `json:"created_at" form:"created_at"`
	UpdateAt        time.Time
}

type Article

type Article struct {
	Id         int64          `json:"id" form:"id"`
	Title      string         `json:"title" form:"title"`
	Content    string         `json:"content" form:"content"`
	CreateAt   int64          `json:"create_at" form:"create_at"`
	UpdateAt   int64          `json:"update_at" form:"update_at"`
	UserId     int64          `json:"user_id" form:"user_id"`
	Category   string         `json:"category" form:"category"`
	TagsString datatypes.JSON `json:"tags_string" form:"tags_string"`
	ViewTimes  int64          `json:"view_times" form:"view_times"`
	Likes      int64          `json:"likes" form:"likes"`
	Dislikes   int64          `json:"dislikes" form:"dislikes"`
}

type Comment

type Comment struct {
	Id       int64  `json:"id" form:"id"`
	Content  string `json:"content" form:"content"`
	CreateAt int64  `json:"create_at" form:"create_at"`
	UpdateAt int64  `json:"update_at" form:"update_at"`
	UserId   int64  `json:"user_id" form:"user_id"`
}

type CommentArchive

type CommentArchive struct {
	Id       int64  `json:"id" form:"id"`
	Content  string `json:"content" form:"content"`
	CreateAt int64  `json:"create_at" form:"create_at"`
	UpdateAt int64  `json:"update_at" form:"update_at"`
	UserId   int64  `json:"user_id" form:"user_id"`
}

type LoginHistory

type LoginHistory struct {
	ID       int64  `json:"id" form:"id"`
	Ip       string `json:"ip" form:"ip"`
	UserId   int64  `json:"user_id" form:"user_id"`
	CreateAt int64  `json:"create_at" form:"create_at"`
	UpdateAt int64  `json:"update_at" form:"update_at"`
	Hostname string `json:"hostname" form:"hostname"`
}

type PaymentHistory

type PaymentHistory struct {
	ID       int64 `json:"id" form:"id"`
	Number   int64 `json:"number" form:"number"`
	UserId   int64 `json:"user_id" form:"user_id"`
	CreateAt int64 `json:"create_at" form:"create_at"`
	UpdateAt int64 `json:"update_at" form:"update_at"`
}

type Role

type Role struct {
	ID        int64     `json:"id" form:"id"`
	Name      string    `json:"name" form:"name"`
	CreatedAt time.Time `json:"created_at" form:"created_at"`
	UpdateAt  time.Time
}

type ScoreHistory

type ScoreHistory struct {
	ID          int64 `json:"id" form:"id"`
	ChangeScore int64 `json:"change_score" form:"change_score"`
	UserId      int64 `json:"user_id" form:"user_id"`
	CreateAt    int64 `json:"create_at" form:"create_at"`
	UpdateAt    int64 `json:"update_at" form:"update_at"`
}

ScoreHistory score history table

type User

type User struct {
	ID              int64  `json:"id" form:"id"`
	Name            string `json:"name" form:"name"`
	Email           string
	Avatar          string `json:"avatar" form:"avatar"`
	EmailVerifiedAt time.Time
	Password        string
	RememberToken   string
	CreatedAt       time.Time `json:"created_at" form:"created_at"`
	UpdateAt        time.Time
}

User is our User example model. Keep note that the tags for public-use (for our web app) should be kept in other file like "web/viewmodels/user.go" which could wrap by embedding the datamodels.User or define completely new fields instead but for the shake of the example, we will use this datamodel as the only one User model in our application.

func (User) IsValid

func (u User) IsValid() bool

IsValid can do some very very simple "low-level" data validations.

type UserToken

type UserToken struct {
	ID         int64  `json:"id" form:"id"`
	Token      string `gorm:"size:32;unique;not null" json:"token" form:"token"`
	UserId     int64  `gorm:"not null;index:idx_user_id;" json:"userId" form:"userId"`
	ExpiredAt  int64  `gorm:"not null" json:"expiredAt" form:"expiredAt"`
	Status     int    `gorm:"not null;index:idx_status" json:"status" form:"status"`
	CreateTime int64  `gorm:"not null" json:"createTime" form:"createTime"`
}

User is our User example model. Keep note that the tags for public-use (for our web app) should be kept in other file like "web/viewmodels/user.go" which could wrap by embedding the datamodels.User or define completely new fields instead but for the shake of the example, we will use this datamodel as the only one User model in our application.

Jump to

Keyboard shortcuts

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