models

package
v0.0.0-...-8596441 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func Md5Pwd

func Md5Pwd(password string) string

Md5Pwd 生成加密密码

func ScryptPwd

func ScryptPwd(password string) string

ScryptPwd 使用scrypt算法生成加密密码

func UserAdd

func UserAdd(useradd *UserAddModel) int

UserAdd 添加用户

func UserChangePassword

func UserChangePassword(id int, data *UserPasswordModel) (int, string)

UserChangePassword 修改用户密码

func UserDel

func UserDel(id int) int

UserDel 删除用户

func UserUpdate

func UserUpdate(id int, data *UserUpdateModel) int

UserUpdate 更新用户

Types

type Article

type Article struct {
	ArticleId    uint           `json:"article_id" gorm:"primaryKey;autoIncrement"`
	Title        string         `json:"title" gorm:"type:VARCHAR(200);comment:'标题'" binding:"required" label:"标题" example:"go语言"`
	Content      string         `` /* 228-byte string literal not displayed */
	Status       int            `json:"status" gorm:"type:TINYINT UNSIGNED;default:1;comment:'状态'" binding:"required" label:"状态" example:"1"`
	PraiseCount  int            `json:"praise_count" gorm:"default:0;comment:'点赞数'" binding:"required" label:"点赞数" example:"10"`
	CommentCount int            `json:"comment_count" gorm:"default:0;comment:'评论数'" binding:"required" label:"评论数" example:"10"`
	CreatedAt    time.Time      `json:"created_at" gorm:"comment:'创建时间'"`
	UpdatedAt    time.Time      `json:"updated_at" gorm:"comment:'更新时间'"`
	DeletedAt    gorm.DeletedAt `json:"deleted_at" gorm:"index;comment:'删除时间'"`
	CategoryId   uint           `json:"category_id" gorm:"comment:'文章分类ID'"`
	UserId       uint           `json:"user_id" gorm:"comment:'用户ID'"`
}

Article 文章

type Category

type Category struct {
	CategoryId uint   `json:"category_id" gorm:"primaryKey;autoIncrement"`
	Name       string `json:"name" gorm:"type:VARCHAR(20);comment:'分类名称'" binding:"required" label:"分类名称" example:"go"`
	UserId     uint   `json:"user_id" gorm:"comment:'用户ID'"`
}

Category 文章分类表

type Comment

type Comment struct {
	CommentId uint      `json:"comment_id" gorm:"primaryKey;autoIncrement"`
	Content   string    `json:"content" gorm:"type:TEXT;comment:'评论内容'" binding:"required" label:"评论内容" example:"观点阐述到位"`
	CreatedAt time.Time `json:"created_at" gorm:"comment:'创建时间'"`
	ArticleId uint      `json:"article_id" gorm:"comment:'文章ID'"`
	UserId    uint      `json:"user_id" gorm:"comment:'用户ID'"`
}

Comment 评论

type HTTPError

type HTTPError struct {
	Code    int    `json:"code" example:"300"`
	Message string `json:"message" example:"请求失败"`
	Data    any    `json:"data"`
}

type Praise

type Praise struct {
	ArticleId uint      `json:"article_id" gorm:"primaryKey;comment:'文章ID'"`
	UserId    uint      `json:"user_id" gorm:"primaryKey;comment:'用户ID'"`
	CreatedAt time.Time `json:"created_at" gorm:"comment:'创建时间'"`
}

Praise 点赞

type Profile

type Profile struct {
	gorm.Model
	Name      string `json:"name" gorm:"varchar(20);comment:'昵称'"`
	Desc      string `json:"desc" gorm:"varchar(200);comment:'简介'"`
	Qqchat    string `json:"qq_chat" gorm:"varchar(100);comment:'QQ号'"`
	Wechat    string `json:"wechat" gorm:"varchar(100);comment:'微信号'"`
	Email     string `json:"email" gorm:"varchar(200);comment:'邮箱'"`
	Img       string `json:"img" gorm:"varchar(200);comment:'图片地址'"`
	Avatar    string `json:"avatar" gorm:"varchar(200);comment:'头像'"`
	IcpRecord string `json:"icp_record" gorm:"varchar(200)"`
}

type User

type User struct {
	UserId    uint         `json:"user_id" gorm:"primaryKey;autoIncrement"`
	Username  string       `` /* 135-byte string literal not displayed */
	Password  string       `` /* 129-byte string literal not displayed */
	Role      uint8        `json:"role" gorm:"type:TINYINT UNSIGNED;not null;default:1;comment:'角色'" binding:"required" label:"角色" example:"3"`
	CreatedAt time.Time    `json:"created_at" gorm:"comment:'创建时间'"`
	UpdatedAt time.Time    `json:"updated_at" gorm:"comment:'更新时间'"`
	DeletedAt sql.NullTime `json:"deleted_at" gorm:"index;comment:'删除时间'"`
}

User 用户

func UserList

func UserList(username string, pageSize int, pageNum int) ([]User, int64)

UserList 用户列表 分页 username 用户名 pageSize 每页显示的条目数 pageNum 页码

func (*User) BeforeCreate

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

BeforeCreate gorm钩子函数,会在创建对象前执行

type UserAddModel

type UserAddModel struct {
	Username string `` /* 135-byte string literal not displayed */
	Password string `` /* 129-byte string literal not displayed */
	Role     uint8  `json:"role" gorm:"type:TINYINT UNSIGNED;not null;default:1;comment:'角色'" binding:"required" label:"角色" example:"3"`
}

func (*UserAddModel) CheckUser

func (u *UserAddModel) CheckUser(username string) int

CheckUser 验证用户是否存在

type UserLoginModel

type UserLoginModel struct {
	Username string `json:"username" binding:"required,min=4,max=50" label:"用户名" example:"admin"`
	Password string `json:"password" binding:"required,min=6,max=18" label:"密码" example:"123456"`
}

func UserLogin

func UserLogin(data *UserLoginModel) (UserLoginModel, int)

UserLogin 用户登录

type UserPasswordModel

type UserPasswordModel struct {
	Password string `json:"password" binding:"required,min=6,max=18" label:"密码" example:"123456"`
}

type UserQueryModel

type UserQueryModel struct {
	Username string `json:"username" binding:"required,min=4,max=50" label:"用户名" example:"test"`
	Role     uint8  `json:"role" binding:"required" label:"角色" example:"3"`
}

func UserQuery

func UserQuery(id int) (UserQueryModel, int)

UserQuery 查询单个用户

type UserUpdateModel

type UserUpdateModel struct {
	Username string `json:"username" binding:"required,min=4,max=50" label:"用户名" example:"test"`
	Role     uint8  `json:"role" binding:"required" label:"角色" example:"3"`
}

func (*UserUpdateModel) CheckUpUser

func (u *UserUpdateModel) CheckUpUser(id int, username string) int

CheckUpUser 更新用户时调用此方法验证用户是否存在

Jump to

Keyboard shortcuts

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