models

package
v0.0.0-...-318ce3a Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeletePostById

func DeletePostById(id int) error

func DeleteUserByUsername

func DeleteUserByUsername(username string) error

func ExistsPostById

func ExistsPostById(id int) bool

func ExistsUserByUsername

func ExistsUserByUsername(username string) bool

func ExistsUserByUsernameOrNicknameOrEmail

func ExistsUserByUsernameOrNicknameOrEmail(username, nickname, email string) bool

func GetNextId

func GetNextId(doc string) int

Types

type Comment

type Comment struct {
	Id       int           `json:"id" bson:"_id"`
	Content  string        `json:"content"`
	Writer   bson.ObjectId `json:"writer"`
	CreateAt time.Time     `json:"create_at"`
	UpdateAt time.Time     `json:"update_at"`
}

func NewComment

func NewComment(content string, writer *User) Comment

type Post

type Post struct {
	Id       int           `json:"id" bson:"_id"`
	Title    string        `json:"title"`
	Content  string        `json:"content"`
	Writer   bson.ObjectId `json:"writer"`
	Comments []Comment     `json:"comments"`
	CreateAt time.Time     `json:"create_at"`
	UpdateAt time.Time     `json:"update_at"`
}

func FindPostById

func FindPostById(id int) *Post

func NewPost

func NewPost(title, content string, writer *User) *Post

func (*Post) AddComment

func (p *Post) AddComment(comment Comment)

func (*Post) Save

func (p *Post) Save() error

type User

type User struct {
	Id       bson.ObjectId `json:"id" bson:"_id"`
	Username string        `json:"username"`
	Password string        `json:"password"`
	Nickname string        `json:"nickname"`
	Email    string        `json:"email"`
	Roles    []string      `json:"roles"`
}

func FindUserById

func FindUserById(id bson.ObjectId) *User

func FindUserByUsername

func FindUserByUsername(username string) *User

func NewUser

func NewUser(username, password, nickname, email string, roles ...string) *User

func (*User) Equals

func (u *User) Equals(t *User) bool

func (*User) Save

func (u *User) Save() error

Jump to

Keyboard shortcuts

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