models

package
v0.0.0-...-c605425 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func CountComment

func CountComment() int

func CountPage

func CountPage() int

func CountPost

func CountPost() int

func CountPostByArchive

func CountPostByArchive(year, month string) (count int, err error)

func CountPostByTag

func CountPostByTag(tag string) (count int, err error)

func CountSubscriber

func CountSubscriber() (int, error)

func CountTag

func CountTag() int

func SetAllCommentRead

func SetAllCommentRead() error

Types

type BaseModel

type BaseModel struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

I don't need soft delete,so I use customized BaseModel instead gorm.Model

type Comment

type Comment struct {
	BaseModel
	UserID    uint   // 用户id
	Content   string // 内容
	PostID    uint   // 文章id
	ReadState bool   `gorm:"default:'0'"` // 阅读状态
	//Replies []*Comment // 评论
	NickName  string `gorm:"-"`
	AvatarUrl string `gorm:"-"`
	GithubUrl string `gorm:"-"`
}

table comments

func ListCommentByPostID

func ListCommentByPostID(postId string) ([]*Comment, error)

func ListUnreadComment

func ListUnreadComment() ([]*Comment, error)

func MustListUnreadComment

func MustListUnreadComment() []*Comment

func (*Comment) Delete

func (comment *Comment) Delete() error

func (*Comment) Insert

func (comment *Comment) Insert() error

Comment

func (*Comment) Update

func (comment *Comment) Update() error

type GithubUserInfo

type GithubUserInfo struct {
	AvatarURL         string `json:"avatar_url"`
	Bio               string `json:"bio"`
	Blog              string `json:"blog"`
	Company           string `json:"company"`
	CreatedAt         string `json:"created_at"`
	Email             string `gorm:"unique_index;default:null" json:"email"`
	EventsURL         string `json:"events_url"`
	Followers         int    `json:"followers"`
	FollowersURL      string `json:"followers_url"`
	Following         int    `json:"following"`
	FollowingURL      string `json:"following_url"`
	GistsURL          string `json:"gists_url"`
	GravatarID        string `gorm:"unique_index;default:null" json:"gravatar_id"`
	Hireable          string `json:"hireable"`
	HTMLURL           string `json:"html_url"`
	ID                int    `json:"id"`
	Location          string `json:"location"`
	Login             string `gorm:"unique_index" json:"login"`
	Name              string `json:"name"`
	OrganizationsURL  string `json:"organizations_url"`
	PublicGists       int    `json:"public_gists"`
	PublicRepos       int    `json:"public_repos"`
	ReceivedEventsURL string `json:"received_events_url"`
	ReposURL          string `json:"repos_url"`
	SiteAdmin         bool   `json:"site_admin"`
	StarredURL        string `json:"starred_url"`
	SubscriptionsURL  string `json:"subscriptions_url"`
	Type              string `json:"type"`
	UpdatedAt         string `json:"updated_at"`
	URL               string `gorm:"default:null" json:"url"`
	UserID            uint
}

Github User Info

type Link struct {
	gorm.Model
	Name string `json:"name" form:"name" validate:"required"`
	Url  string `json:"url" form:"url" validate:"required,url"`
	Sort int    `gorm:"default:'0'"` //排序
	View int    //访问次数
}

table link

func ListLinks() ([]*Link, error)
func MustListLinks() []*Link

func (*Link) Delete

func (link *Link) Delete() error

func (*Link) Insert

func (link *Link) Insert() error

Link

func (*Link) Update

func (link *Link) Update() error

type Page

type Page struct {
	gorm.Model
	Title        string `json:"title" form:"title" validate:"required"` // title
	Body         string `json:"body" form:"body"`                       // body
	View         int    `form:"-" json:"-"`                             // view count
	IsPublished  bool   `json:"is_published" form:"is_published"`       // published or not
	CommentTotal int    `gorm:"-"`                                      // count of comment
	LikeTotal    int    `gorm:"_"`
}

table pages

func ListPublishedPage

func ListPublishedPage() ([]*Page, error)

func (*Page) UpdateView

func (page *Page) UpdateView() error

type Post

type Post struct {
	BaseModel
	Title        string     `json:"title" form:"title" validate:"required"` // title
	Body         string     `json:"body"  form:"body"  validate:"required"` // body
	View         int        // view count
	IsPublished  bool       `json:"is_published" form:"is_published"`
	PostTags     []*PostTag `gorm:""`
	Tags         []*Tag     `gorm:"many2many:post_tags;"` // tags of post
	Comments     []*Comment `gorm:"-"`                    // comments of post
	CommentTotal int        `gorm:"-"`                    // count of comment
	LikeTotal    int        `gorm:"_"`
	Keyword      string     `gorm:"size:255;not null" json:"keyword" form:"keyword" validate:"required"`
}

func GetPostById

func GetPostById(id string) (*Post, error)

通过Id查询博文

func ListMaxCommentPost

func ListMaxCommentPost() (posts []*Post, err error)

func ListMaxReadPost

func ListMaxReadPost() (posts []*Post, err error)

func ListPostByArchive

func ListPostByArchive(year, month string, pageIndex, pageSize int) ([]*Post, error)

func ListPublishedPost

func ListPublishedPost(tag string, pageIndex, pageSize int) ([]*Post, error)

获取已发布的博文

func MustListMaxCommentPost

func MustListMaxCommentPost() (posts []*Post)

func MustListMaxReadPost

func MustListMaxReadPost() (posts []*Post)

func (*Post) Delete

func (post *Post) Delete() error

删除博文

func (*Post) Excerpt

func (post *Post) Excerpt() template.HTML

func (*Post) Insert

func (post *Post) Insert() error

Post

func (*Post) Update

func (post *Post) Update() error

func (*Post) UpdateView

func (post *Post) UpdateView() error

更新博文阅读数量

type PostTag

type PostTag struct {
	BaseModel
	PostId uint // post id
	TagId  uint // tag id
}

table post_tags

func (*PostTag) Insert

func (pt *PostTag) Insert() error

post_tags

type QrArchive

type QrArchive struct {
	ArchiveDate time.Time //month
	Total       int       //total
	Year        int       // year
	Month       int       // month
}

query result

func ListPostArchives

func ListPostArchives() ([]*QrArchive, error)

func MustListPostArchives

func MustListPostArchives() []*QrArchive

type SmmsFile

type SmmsFile struct {
	BaseModel
	FileName  string `json:"filename"`
	StoreName string `json:"storename"`
	Size      int    `json:"size"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Hash      string `json:"hash"`
	Delete    string `json:"delete"`
	Url       string `json:"url"`
	Path      string `json:"path"`
}

func (SmmsFile) Insert

func (sf SmmsFile) Insert() (err error)

type Subscriber

type Subscriber struct {
	gorm.Model
	Email          string    `gorm:"unique_index" json:"email" form:"email"`                     //邮箱
	VerifyState    bool      `gorm:"default:'0'" json:"verify_state" form:"verify_state" `       //验证状态
	SubscribeState bool      `gorm:"default:'1'" json:"subscribe_state" form:"subscribe_state" ` //订阅状态
	OutTime        time.Time //过期时间
	SecretKey      string    // 秘钥
	Signature      string    //签名
}

table subscribe

func GetSubscriberByEmail

func GetSubscriberByEmail(mail string) (*Subscriber, error)

func GetSubscriberById

func GetSubscriberById(id uint) (*Subscriber, error)

func GetSubscriberBySignature

func GetSubscriberBySignature(key string) (*Subscriber, error)

func ListSubscriber

func ListSubscriber(invalid bool) ([]*Subscriber, error)

func (*Subscriber) Insert

func (s *Subscriber) Insert() error

Subscriber

func (*Subscriber) Update

func (s *Subscriber) Update() error

type Tag

type Tag struct {
	BaseModel
	Name  string  `gorm:"UNIQUE_INDEX;not null" json:"name" form:"name" validate:"required"` // tag name
	Total int     `gorm:"-" json:"total" form:"total"`                                       // count of post
	Posts []*Post `gorm:"many2many:post_tags;"`
}

table tags

func ListTag

func ListTag() ([]*Tag, error)

func ListTagByPostId

func ListTagByPostId(id string) ([]*Tag, error)

func MustListTag

func MustListTag() []*Tag

func (*Tag) Insert

func (tag *Tag) Insert() error

Tag

type User

type User struct {
	gorm.Model
	Email              string    `gorm:"unique_index;default:null" json:"email" form:"email" validate:"required,email"`   //邮箱
	Telephone          string    `gorm:"unique_index;default:null" json:"telephone" form:"telephone" validate:"required"` //手机号码
	Password           string    `gorm:"default:null" json:"password" form:"password" validate:"required"`                //密码
	VerifyState        string    `gorm:"default:'0'" json:"verify_state"`                                                 //邮箱验证状态
	SecretKey          string    `gorm:"default:null" form:"secret_key"  json:"secret_key"`                               //密钥
	OutTime            time.Time //过期时间
	GithubLoginId      string    `gorm:"unique_index;default:null" json:"github_login_id"` // github唯一标识
	GithubUrl          string    //github地址
	IsAdmin            bool      //是否是管理员
	AvatarUrl          string    `form:"avatar_url" json:"avatar_url"` // 头像链接
	NickName           string    `form:"nick_name" json:"nick_name"`   // 昵称
	LockState          bool      `gorm:"default:'0'"`                  //锁定状态
	ModifyPasswordHash string    `gorm:"default:null"`
	ModifyPasswordTime time.Time `gorm:"default:'1990-01-01 00:00:00'"`
	GithubUserInfo     GithubUserInfo
}

table users

func (*User) FirstOrCreate

func (u *User) FirstOrCreate() (*User, error)

func (*User) Insert

func (u *User) Insert() error

user insert user

func (*User) ShowAvatarURL

func (u *User) ShowAvatarURL() string

显示用户的AvatarUrl

func (*User) Update

func (u *User) Update() error

update user

Jump to

Keyboard shortcuts

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