model

package
v0.0.0-...-b7604bf Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ISO8601 = "2006-01-02T15:04:05-0700Z"

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	gorm.Model
	Title          string `gorm:"not null"`
	Description    string `gorm:"not null"`
	Body           string `gorm:"not null"`
	Tags           []Tag  `gorm:"many2many:article_tags"`
	Author         User   `gorm:"foreignkey:UserID"`
	UserID         uint   `gorm:"not null"`
	FavoritesCount int32  `gorm:"not null;default=0"`
	FavoritedUsers []User `gorm:"many2many:favorite_articles"`
	Comments       []Comment
}

Article model

func (*Article) Overwrite

func (a *Article) Overwrite(title, description, body string)

Overwrite overwrite each field if it's not zero-value

func (*Article) ProtoArticle

func (a *Article) ProtoArticle(favorited bool) *pb.Article

ProtoArticle generates proto aritcle model from article

func (Article) Validate

func (a Article) Validate() error

Validate validates fields of article model

type Comment

type Comment struct {
	gorm.Model
	Body      string `gorm:"not null"`
	UserID    uint   `gorm:"not null"`
	Author    User   `gorm:"foreignkey:UserID"`
	ArticleID uint   `gorm:"not null"`
	Article   Article
}

Comment model

func (*Comment) ProtoComment

func (c *Comment) ProtoComment() *pb.Comment

ProtoComment generates proto comment model from article

func (Comment) Validate

func (c Comment) Validate() error

Validate validates fields of comment model

type Tag

type Tag struct {
	gorm.Model
	Name string `gorm:"not null"`
}

Tag model

type User

type User struct {
	gorm.Model
	Username         string    `gorm:"unique_index;not null"`
	Email            string    `gorm:"unique_index;not null"`
	Password         string    `gorm:"not null"`
	Bio              string    `gorm:"not null"`
	Image            string    `gorm:"not null"`
	Follows          []User    `gorm:"many2many:follows;jointable_foreignkey:from_user_id;association_jointable_foreignkey:to_user_id"`
	FavoriteArticles []Article `gorm:"many2many:favorite_articles;"`
}

User is user model

func (*User) CheckPassword

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

CheckPassword checki user password correct

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword makes password field crypted

func (*User) ProtoProfile

func (u *User) ProtoProfile(following bool) *pb.Profile

ProtoProfile generates proto profile model from user

func (*User) ProtoUser

func (u *User) ProtoUser(token string) *pb.User

ProtoUser generates proto user model from user

func (User) Validate

func (u User) Validate() error

Validate validates fields of user model

Jump to

Keyboard shortcuts

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