models

package
v0.0.0-...-7bbc56a Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID        uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Name      string    `gorm:"size:256;uniqueIndex:idx_name;not null" json:"name"`
	Posts     []Post    `gorm:"many2many:post_categories" json:"posts"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Deleted   gorm.DeletedAt
}

Category the category for post.

func (*Category) Delete

func (c *Category) Delete(db *gorm.DB) error

Delete a category.

func (*Category) FindCategories

func (c *Category) FindCategories(db *gorm.DB) (*[]Category, error)

FindCategories returns a list of categories in first 100 results.

func (*Category) FindCategoriesByName

func (c *Category) FindCategoriesByName(db *gorm.DB, name string) (*[]Category, error)

FindCategoriesByName returns a list of categories by name.

func (*Category) FindCategoryByID

func (c *Category) FindCategoryByID(db *gorm.DB) (*Category, error)

FindCategoryByID find a specific category by ID.

func (*Category) SaveCategory

func (c *Category) SaveCategory(db *gorm.DB) (*Category, error)

SaveCategory save category information to database.

func (*Category) UpdateCategory

func (c *Category) UpdateCategory(db *gorm.DB) error

UpdateCategory updates a category.

func (*Category) Validate

func (c *Category) Validate() error

Validate validates the category

type Comment

type Comment struct {
	ID        uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Title     string    `gorm:"size:256;not null;index:idx_title" json:"title"`
	Content   string    `gorm:"not null" json:"content"`
	PostID    uint64    `gorm:"not null;index:idx_post_id" json:"post_id"`
	UserID    uint64    `gorm:"not null;index:idx_user_id" json:"user_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Deleted   gorm.DeletedAt
}

Comment comments for a post.

func (*Comment) DeleteComment

func (c *Comment) DeleteComment(db *gorm.DB) error

DeleteComment deletes a comment.

func (*Comment) FindCommentByID

func (c *Comment) FindCommentByID(db *gorm.DB) (*Comment, error)

FindCommentByID returns a comment by id.

func (*Comment) FindCommentsBy

func (c *Comment) FindCommentsBy(db *gorm.DB) (*[]Comment, error)

FindCommentsBy returns a list of comments by criterias.

func (*Comment) SaveComment

func (c *Comment) SaveComment(db *gorm.DB) (*Comment, error)

SaveComment Create a comment.

curl -i -X POST \
  http://127.0.0.1:8080/api/v1/comments/\?pid\=1\&uid\=1 \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
        "title":"comment title II","content":"comment content","post_id":1,"user_id":1
}'

func (*Comment) UpdateComment

func (c *Comment) UpdateComment(db *gorm.DB) error

UpdateComment updates a comment.

type Like

type Like struct {
	ID        uint64    `gorm:"primary_key;auto_increment" json:"id"`
	PostID    uint64    `gorm:"not null;index:idx_post_id" json:"post_id"`
	UserID    uint64    `gorm:"not null;index:idx_user_id" json:"user_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Deleted   gorm.DeletedAt
}

Like A user like a post

func (*Like) DeleteLike

func (l *Like) DeleteLike(db *gorm.DB) error

DeleteLike deletes a Like object

func (*Like) FindLikeByID

func (l *Like) FindLikeByID(db *gorm.DB) (*Like, error)

FindLikeByID returns a Like by id

func (*Like) FindLikesBy

func (l *Like) FindLikesBy(db *gorm.DB) (*[]Like, error)

FindLikesBy returns a list of Like by user id or post id.

func (*Like) SaveLikes

func (l *Like) SaveLikes(db *gorm.DB) (*Like, error)

SaveLikes creates a new Like.

func (*Like) UpdateLike

func (l *Like) UpdateLike(db *gorm.DB) error

UpdateLike updates a Like object

type Post

type Post struct {
	ID         uint64     `gorm:"primary_key;auto_increment" json:"id"`
	Title      string     `gorm:"size:256;not null;index:idx_title" json:"title"`
	Summary    string     `gorm:"not null" json:"summary"`
	Content    string     `gorm:"not null" json:"content"`
	Categories []Category `gorm:"not null;many2many:post_categories" json:"categories"`
	Comments   []Comment  `json:"comments"`
	Likes      []Like     `json:"likes"`
	UserID     uint64     `gorm:"not null;index:idx_user_id" json:"user_id"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
	Deleted    gorm.DeletedAt
}

Post post struct

func (*Post) DeletePost

func (p *Post) DeletePost(db *gorm.DB) error

DeletePost deletes a post.

func (*Post) FindPostByID

func (p *Post) FindPostByID(db *gorm.DB) (*Post, error)

FindPostByID find posts by post id.

func (*Post) FindPosts

func (p *Post) FindPosts(db *gorm.DB) (*[]Post, error)

FindPosts returns the top 100 posts.

func (*Post) FindPostsByCategory

func (p *Post) FindPostsByCategory(db *gorm.DB, cid uint64) (*[]Post, error)

FindPostsByCategory find posts by specific category.

func (*Post) FindPostsByTitle

func (p *Post) FindPostsByTitle(db *gorm.DB, title string) (*[]Post, error)

FindPostsByTitle return posts by title.

func (*Post) FindPostsByUser

func (p *Post) FindPostsByUser(db *gorm.DB, uid uint64) (*[]Post, error)

FindPostsByUser find posts by user.

func (*Post) SavePost

func (p *Post) SavePost(db *gorm.DB, uid uint64, cids []uint64) (*Post, error)

SavePost save a post data in database.

func (*Post) UpdatePost

func (p *Post) UpdatePost(db *gorm.DB) error

UpdatePost updates a post.

func (*Post) Validate

func (p *Post) Validate() error

Validate validates the post data.

type User

type User struct {
	ID        uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Username  string    `gorm:"size:256;not null;uniqueIndex:idx_userame;" json:"username"`
	Password  string    `gorm:"size:256;not null" json:"password"`
	Nickname  string    `gorm:"size:256;uniqueIndex:idx_nickname;" json:"nickname"`
	Type      uint8     `gorm:"not null;index:idx_type;default:1;comment:1:user, 2:admin" json:"type"`
	Mobile    string    `gorm:"size:16;not null;uniqueIndex:idx_mobile;" json:"mobile"`
	Email     string    `gorm:"size:128;not null;uniqueIndex:idx_email;" json:"email"`
	Posts     []Post    `json:"posts"`
	Likes     []Like    `json:"likes"`
	Comments  []Comment `json:"comments"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Deleted   gorm.DeletedAt
}

User represents a user.

func (*User) DeleteUser

func (u *User) DeleteUser(db *gorm.DB) error

DeleteUser deletes a user.

func (*User) FindUserByID

func (u *User) FindUserByID(db *gorm.DB) (*User, error)

FindUserByID returns a user matching specific ID.

func (*User) FindUsers

func (u *User) FindUsers(db *gorm.DB) (*[]User, error)

FindUsers returns a list of top 100 users.

func (*User) FindUsersBy

func (u *User) FindUsersBy(db *gorm.DB) (*[]User, error)

FindUsersBy returns a list of users matching the specific conditions.

func (*User) SaveUser

func (u *User) SaveUser(db *gorm.DB) (*User, error)

SaveUser create a new user.

func (*User) UpdateUser

func (u *User) UpdateUser(db *gorm.DB) error

UpdateUser updates a user.

func (*User) Validate

func (u *User) Validate() error

Validate validates the user's struct.

Jump to

Keyboard shortcuts

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