articles

package
v0.0.0-...-f8a9cde Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

The article module containing the article CRUD operation and relationship CRUD.

model.go: definition of orm based data model

routers.go: router binding and core logic

serializers.go: definition the schema of return data

validators.go: definition the validator of form data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArticleCommentCreate

func ArticleCommentCreate(c *gin.Context)

func ArticleCommentDelete

func ArticleCommentDelete(c *gin.Context)

func ArticleCommentList

func ArticleCommentList(c *gin.Context)

func ArticleCreate

func ArticleCreate(c *gin.Context)

func ArticleDelete

func ArticleDelete(c *gin.Context)

func ArticleFavorite

func ArticleFavorite(c *gin.Context)

func ArticleFeed

func ArticleFeed(c *gin.Context)

func ArticleList

func ArticleList(c *gin.Context)

func ArticleRetrieve

func ArticleRetrieve(c *gin.Context)

func ArticleUnfavorite

func ArticleUnfavorite(c *gin.Context)

func ArticleUpdate

func ArticleUpdate(c *gin.Context)

func ArticlesAnonymousRegister

func ArticlesAnonymousRegister(router *gin.RouterGroup)

func ArticlesRegister

func ArticlesRegister(router *gin.RouterGroup)

func DeleteArticleModel

func DeleteArticleModel(condition interface{}) error

func DeleteCommentModel

func DeleteCommentModel(condition interface{}) error

func SaveOne

func SaveOne(data interface{}) error

func TagList

func TagList(c *gin.Context)

func TagsAnonymousRegister

func TagsAnonymousRegister(router *gin.RouterGroup)

Types

type ArticleModel

type ArticleModel struct {
	gorm.Model
	Slug        string `gorm:"unique_index"`
	Title       string
	Description string `gorm:"size:2048"`
	Body        string `gorm:"size:2048"`
	Author      ArticleUserModel
	AuthorID    uint
	Tags        []TagModel     `gorm:"many2many:article_tags;"`
	Comments    []CommentModel `gorm:"ForeignKey:ArticleID"`
}

func FindManyArticle

func FindManyArticle(tag, author, limit, offset, favorited string) ([]ArticleModel, int, error)

func FindOneArticle

func FindOneArticle(condition interface{}) (ArticleModel, error)

func (*ArticleModel) Update

func (model *ArticleModel) Update(data interface{}) error

type ArticleModelValidator

type ArticleModelValidator struct {
	Article struct {
		Title       string   `form:"title" json:"title" binding:"exists,min=4"`
		Description string   `form:"description" json:"description" binding:"max=2048"`
		Body        string   `form:"body" json:"body" binding:"max=2048"`
		Tags        []string `form:"tagList" json:"tagList"`
	} `json:"article"`
	// contains filtered or unexported fields
}

func NewArticleModelValidator

func NewArticleModelValidator() ArticleModelValidator

func NewArticleModelValidatorFillWith

func NewArticleModelValidatorFillWith(articleModel ArticleModel) ArticleModelValidator

func (*ArticleModelValidator) Bind

func (s *ArticleModelValidator) Bind(c *gin.Context) error

type ArticleResponse

type ArticleResponse struct {
	ID             uint                  `json:"-"`
	Title          string                `json:"title"`
	Slug           string                `json:"slug"`
	Description    string                `json:"description"`
	Body           string                `json:"body"`
	CreatedAt      string                `json:"createdAt"`
	UpdatedAt      string                `json:"updatedAt"`
	Author         users.ProfileResponse `json:"author"`
	Tags           []string              `json:"tagList"`
	Favorite       bool                  `json:"favorited"`
	FavoritesCount uint                  `json:"favoritesCount"`
}

type ArticleSerializer

type ArticleSerializer struct {
	C *gin.Context
	ArticleModel
}

func (*ArticleSerializer) Response

func (s *ArticleSerializer) Response() ArticleResponse

type ArticleUserModel

type ArticleUserModel struct {
	gorm.Model
	UserModel      users.UserModel
	UserModelID    uint
	ArticleModels  []ArticleModel  `gorm:"ForeignKey:AuthorID"`
	FavoriteModels []FavoriteModel `gorm:"ForeignKey:FavoriteByID"`
}

func GetArticleUserModel

func GetArticleUserModel(userModel users.UserModel) ArticleUserModel

func (*ArticleUserModel) GetArticleFeed

func (self *ArticleUserModel) GetArticleFeed(limit, offset string) ([]ArticleModel, int, error)

type ArticleUserSerializer

type ArticleUserSerializer struct {
	C *gin.Context
	ArticleUserModel
}

func (*ArticleUserSerializer) Response

type ArticlesSerializer

type ArticlesSerializer struct {
	C        *gin.Context
	Articles []ArticleModel
}

func (*ArticlesSerializer) Response

func (s *ArticlesSerializer) Response() []ArticleResponse

type CommentModel

type CommentModel struct {
	gorm.Model
	Article   ArticleModel
	ArticleID uint
	Author    ArticleUserModel
	AuthorID  uint
	Body      string `gorm:"size:2048"`
}

type CommentModelValidator

type CommentModelValidator struct {
	Comment struct {
		Body string `form:"body" json:"body" binding:"max=2048"`
	} `json:"comment"`
	// contains filtered or unexported fields
}

func NewCommentModelValidator

func NewCommentModelValidator() CommentModelValidator

func (*CommentModelValidator) Bind

func (s *CommentModelValidator) Bind(c *gin.Context) error

type CommentResponse

type CommentResponse struct {
	ID        uint                  `json:"id"`
	Body      string                `json:"body"`
	CreatedAt string                `json:"createdAt"`
	UpdatedAt string                `json:"updatedAt"`
	Author    users.ProfileResponse `json:"author"`
}

type CommentSerializer

type CommentSerializer struct {
	C *gin.Context
	CommentModel
}

func (*CommentSerializer) Response

func (s *CommentSerializer) Response() CommentResponse

type CommentsSerializer

type CommentsSerializer struct {
	C        *gin.Context
	Comments []CommentModel
}

func (*CommentsSerializer) Response

func (s *CommentsSerializer) Response() []CommentResponse

type FavoriteModel

type FavoriteModel struct {
	gorm.Model
	Favorite     ArticleModel
	FavoriteID   uint
	FavoriteBy   ArticleUserModel
	FavoriteByID uint
}

type TagModel

type TagModel struct {
	gorm.Model
	Tag           string         `gorm:"unique_index"`
	ArticleModels []ArticleModel `gorm:"many2many:article_tags;"`
}

type TagSerializer

type TagSerializer struct {
	C *gin.Context
	TagModel
}

func (*TagSerializer) Response

func (s *TagSerializer) Response() string

type TagsSerializer

type TagsSerializer struct {
	C    *gin.Context
	Tags []TagModel
}

func (*TagsSerializer) Response

func (s *TagsSerializer) Response() []string

Jump to

Keyboard shortcuts

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