model

package
v0.0.0-...-2a4dbc0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *gorm.DB
)

Functions

func CreateAdministrator

func CreateAdministrator()

CreateAdministrator 创建管理员账户

func CreateComment

func CreateComment(data *Comment) error

CreateComment 新增评论

func CreatePost

func CreatePost(data *Post) error

CreatePost 创建一条post

func CreateSite

func CreateSite(data *Site) error

CreateSite 新增站点

func CreateUser

func CreateUser(data *User) error

CreateUser 新增用户

func DeleteCommentByID

func DeleteCommentByID(id uint) error

DeleteCommentByID 根据ID删除评论及其所有子评论

func DeleteSiteById

func DeleteSiteById(id uint) error

DeleteSiteById 根据Id删除站点

func InitDatabase

func InitDatabase()

InitDatabase 初始化数据库连接

func UpdateCommentByID

func UpdateCommentByID(id uint, data *Comment) error

UpdateCommentByID 根据ID更新评论

func UpdateSiteById

func UpdateSiteById(id uint, site *Site) error

UpdateSiteById 根据ID修改站点信息

func UpdateUser

func UpdateUser(id uint, data map[string]interface{}) error

UpdateUser 更新用户信息

Types

type Comment

type Comment struct {
	Content string
	UA      string
	IP      string
	Region  string
	Type    string `gorm:"default:published"`
	Up      int
	Down    int

	PostID uint `gorm:"index"` // 外键,指向 Post
	Post   Post `gorm:"foreignKey:PostID"`
	UserID uint `gorm:"index"` // 外键,指向 User
	User   User `gorm:"foreignKey:UserID"`

	Parent uint `gorm:"index;default:0"`
	gorm.Model
}

func GetCommentByID

func GetCommentByID(id uint) (*Comment, error)

GetCommentByID 根据ID查找评论

type Post

type Post struct {
	Slug     string `gorm:"index;size:255"`
	Up       int
	Down     int
	Read     int
	SiteID   uint      `gorm:"index"` // 外键,指向 Site
	Site     Site      `gorm:"foreignKey:SiteID"`
	Comments []Comment `gorm:"foreignKey:PostID"` // 定义一对多关系
	gorm.Model
}

func FindOrCreatePost

func FindOrCreatePost(data dto.CommentDTO) (*Post, error)

FindOrCreatePost 查找或创建

func GetPostBySlug

func GetPostBySlug(slug string) (*Post, error)

GetPostBySlug 根据slug获取post

type Site

type Site struct {
	Url   string `gorm:"uniqueIndex;size:255"` // 站点URL
	Name  string
	Posts []Post `gorm:"foreignKey:SiteID"` // 站点下的文章
	gorm.Model
}

func FindSiteByID

func FindSiteByID(id uint) (*Site, error)

FindSiteByID 根据id查找站点

func FindSiteByURL

func FindSiteByURL(url string) (*Site, error)

FindSiteByURL 根据url查找站点

type User

type User struct {
	gorm.Model
	Name     string `gorm:"index;size:255"`
	Email    string `gorm:"index;size:255"`
	Url      string
	Password string
	LastIP   string
	LastUA   string
	Role     string
	Notice   bool `gorm:"default:false"`

	Comments []Comment `gorm:"foreignKey:UserID"` // 用户评论
}

User 用户表

func FindOrCreateUser

func FindOrCreateUser(data dto.CommentDTO) (*User, error)

FindOrCreateUser 查找或创建

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail 通过用户email找到用户信息

func GetUserByID

func GetUserByID(id uint) (*User, error)

GetUserByID 通过用户id找到用户信息

func GetUserByName

func GetUserByName(name string) (*User, error)

GetUserByName 通过用户Name找到用户信息

func GetUserByNameOrEmail

func GetUserByNameOrEmail(nameOrEmail string) (*User, error)

GetUserByNameOrEmail 通过name或email查找用户

func (*User) CheckPassword

func (u *User) CheckPassword(input string) bool

func (*User) SetPasswordEncrypt

func (u *User) SetPasswordEncrypt(password string) (err error)

SetPasswordEncrypt 设置密码加密

Jump to

Keyboard shortcuts

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