Documentation ¶
Index ¶
- type Category
- func (c *Category) Delete(db *gorm.DB) error
- func (c *Category) FindCategories(db *gorm.DB) (*[]Category, error)
- func (c *Category) FindCategoriesByName(db *gorm.DB, name string) (*[]Category, error)
- func (c *Category) FindCategoryByID(db *gorm.DB) (*Category, error)
- func (c *Category) SaveCategory(db *gorm.DB) (*Category, error)
- func (c *Category) UpdateCategory(db *gorm.DB) error
- func (c *Category) Validate() error
- type Comment
- type Like
- type Post
- func (p *Post) DeletePost(db *gorm.DB) error
- func (p *Post) FindPostByID(db *gorm.DB) (*Post, error)
- func (p *Post) FindPosts(db *gorm.DB) (*[]Post, error)
- func (p *Post) FindPostsByCategory(db *gorm.DB, cid uint64) (*[]Post, error)
- func (p *Post) FindPostsByTitle(db *gorm.DB, title string) (*[]Post, error)
- func (p *Post) FindPostsByUser(db *gorm.DB, uid uint64) (*[]Post, error)
- func (p *Post) SavePost(db *gorm.DB, uid uint64, cids []uint64) (*Post, error)
- func (p *Post) UpdatePost(db *gorm.DB) error
- func (p *Post) Validate() error
- type User
- func (u *User) DeleteUser(db *gorm.DB) error
- func (u *User) FindUserByID(db *gorm.DB) (*User, error)
- func (u *User) FindUsers(db *gorm.DB) (*[]User, error)
- func (u *User) FindUsersBy(db *gorm.DB) (*[]User, error)
- func (u *User) SaveUser(db *gorm.DB) (*User, error)
- func (u *User) UpdateUser(db *gorm.DB) error
- func (u *User) Validate() error
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) FindCategories ¶
FindCategories returns a list of categories in first 100 results.
func (*Category) FindCategoriesByName ¶
FindCategoriesByName returns a list of categories by name.
func (*Category) FindCategoryByID ¶
FindCategoryByID find a specific category by ID.
func (*Category) SaveCategory ¶
SaveCategory save category information to database.
func (*Category) UpdateCategory ¶
UpdateCategory updates a 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 ¶
DeleteComment deletes a comment.
func (*Comment) FindCommentByID ¶
FindCommentByID returns a comment by id.
func (*Comment) FindCommentsBy ¶
FindCommentsBy returns a list of comments by criterias.
func (*Comment) SaveComment ¶
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 }'
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 ¶
DeleteLike deletes a Like object
func (*Like) FindLikeByID ¶
FindLikeByID returns a Like by id
func (*Like) FindLikesBy ¶
FindLikesBy returns a list of Like by user id or post id.
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) FindPostByID ¶
FindPostByID find posts by post id.
func (*Post) FindPostsByCategory ¶
FindPostsByCategory find posts by specific category.
func (*Post) FindPostsByTitle ¶
FindPostsByTitle return posts by title.
func (*Post) FindPostsByUser ¶
FindPostsByUser find posts by user.
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) FindUserByID ¶
FindUserByID returns a user matching specific ID.
func (*User) FindUsersBy ¶
FindUsersBy returns a list of users matching the specific conditions.