articles

package
v0.0.0-...-3d9bb29 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsArticlePublishStatus validator.Func = func(fl validator.FieldLevel) bool {
	value := fmt.Sprintf("%s", fl.Field().Interface())
	return value == string(DRAFT) || value == string(PUBLISHED) || value == string(ARCHIVED)
}

Functions

func InjectUserId

func InjectUserId(c *gin.Context, userId *int)

Types

type Article

type Article struct {
	gorm.Model
	Title   string               `gorm:"size:255;not null;index:idx_article_title"`
	Content string               `gorm:"type:text;not null"`
	Slug    string               `gorm:"size:255;not null;uniqueIndex:idx_article_slug"`
	Status  ArticlePublishStatus `gorm:"size:255;not null"`

	AuthorId int
	Author   users.User `gorm:"foreignKey:AuthorId;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}

type ArticleDto

type ArticleDto struct {
	ID        uint                 `json:"id"`
	AuthorId  uint                 `json:"authorId"`
	Title     string               `json:"title"`
	Content   string               `json:"content"`
	Slug      string               `json:"slug"`
	Status    ArticlePublishStatus `json:"status"`
	CreatedAt time.Time            `json:"createdAt"`
	UpdatedAt time.Time            `json:"updatedAt"`
}

type ArticleHandler

type ArticleHandler struct {
	Usecase ArticleUseCase
}

func ConstructArticlesHandler

func ConstructArticlesHandler(router *gin.Engine, usecase ArticleUseCase, jwtAuth authentication.IJwtAuth) ArticleHandler

func (*ArticleHandler) Create

func (u *ArticleHandler) Create(c *gin.Context)

@Summary Create article @Description Create single article @Tags articles @Accepts json @Produce json @Param body body string true "Article body" @Router /api/v1/articles [post]

func (*ArticleHandler) Delete

func (u *ArticleHandler) Delete(c *gin.Context)

@Summary Delete an article @Description Delete single article @Tags articles @Produce json @Param id path int true "Unique article ID" @Router /api/v1/articles/:id [delete]

func (*ArticleHandler) FindAll

func (u *ArticleHandler) FindAll(c *gin.Context)

@Summary Find all articles @Description Find all matching articles @Tags articles @Produce json @Param keyword path string false "Keyword to search" @Param page path int false "Page number" @Param limit path int false "Number of items per page" @Router /api/v1/articles/ [get] @Security JwtAuth

func (*ArticleHandler) Get

func (u *ArticleHandler) Get(c *gin.Context)

@Summary Show article @Description Get single article @Tags articles @Produce json @Param id path int true "Unique article ID" @Router /api/v1/articles/:id [get]

func (*ArticleHandler) Save

func (u *ArticleHandler) Save(c *gin.Context)

@Summary Save article @Description Update single article @Tags articles @Accepts json @Produce json @Param body body string true "Article body" @Router /api/v1/articles [put]

type ArticleItemDto

type ArticleItemDto struct {
	ID        uint                 `json:"id"`
	AuthorId  uint                 `json:"authorId"`
	Title     string               `json:"title"`
	Slug      string               `json:"slug"`
	Status    ArticlePublishStatus `json:"status"`
	CreatedAt time.Time            `json:"createdAt"`
	UpdatedAt time.Time            `json:"updatedAt"`
}

type ArticlePublishStatus

type ArticlePublishStatus string
const (
	DRAFT     ArticlePublishStatus = "DRAFT"
	PUBLISHED ArticlePublishStatus = "PUBLISHED"
	ARCHIVED  ArticlePublishStatus = "ARCHIVED"
)

type ArticleUseCase

type ArticleUseCase interface {
	FindAll(c context.Context, model FindAllModel) (response utils.Response)
	Get(c context.Context, model GetModel) (response utils.Response)
	Create(c context.Context, model CreateModel) (response utils.Response)
	Save(c context.Context, model SaveModel) (response utils.Response)
	Delete(c context.Context, model DeleteModel) (response utils.Response)
}

func ConstructArticlesUseCase

func ConstructArticlesUseCase(db *gorm.DB) ArticleUseCase

type ArticleUseCaseImpl

type ArticleUseCaseImpl struct {
	Database *gorm.DB
}

func (*ArticleUseCaseImpl) Create

func (u *ArticleUseCaseImpl) Create(c context.Context, model CreateModel) (response utils.Response)

func (*ArticleUseCaseImpl) Delete

func (u *ArticleUseCaseImpl) Delete(c context.Context, model DeleteModel) (response utils.Response)

func (*ArticleUseCaseImpl) FindAll

func (u *ArticleUseCaseImpl) FindAll(c context.Context, model FindAllModel) (response utils.Response)

func (*ArticleUseCaseImpl) Get

func (u *ArticleUseCaseImpl) Get(c context.Context, model GetModel) (response utils.Response)

func (*ArticleUseCaseImpl) Save

type CreateModel

type CreateModel struct {
	UserId  int
	Title   string               `json:"title" binding:"required,min=5,max=255"`
	Content string               `json:"content" binding:"required,min=10"`
	Slug    string               `json:"slug" binding:"required,min=5,max=255"`
	Status  ArticlePublishStatus `json:"status" binding:"required,isarticlepublishstatus"`
}

type DeleteModel

type DeleteModel struct {
	UserId    int
	ArticleId int `uri:"id" binding:"required,numeric"`
}

type FindAllModel

type FindAllModel struct {
	UserId  int
	Keyword string `form:"keyword"`
	Page    int    `form:"page" binding:"omitempty,numeric,min=1"`
	Limit   int    `form:"limit" binding:"omitempty,numeric,min=1"`
}

type GetModel

type GetModel struct {
	UserId    int
	ArticleId int `uri:"id" binding:"required,numeric"`
}

type SaveModel

type SaveModel struct {
	UserId    int
	ArticleId int                  `json:"id" binding:"required,numeric"`
	Title     string               `json:"title" binding:"omitempty,min=5,max=255"`
	Content   string               `json:"content" binding:"omitempty,min=10"`
	Slug      string               `json:"slug" binding:"omitempty,min=5,max=255"`
	Status    ArticlePublishStatus `json:"status" binding:"omitempty,isarticlepublishstatus"`
}

Jump to

Keyboard shortcuts

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