Documentation ¶
Index ¶
- Variables
- func InjectUserId(c *gin.Context, userId *int)
- type Article
- type ArticleDto
- type ArticleHandler
- type ArticleItemDto
- type ArticlePublishStatus
- type ArticleUseCase
- type ArticleUseCaseImpl
- func (u *ArticleUseCaseImpl) Create(c context.Context, model CreateModel) (response utils.Response)
- func (u *ArticleUseCaseImpl) Delete(c context.Context, model DeleteModel) (response utils.Response)
- func (u *ArticleUseCaseImpl) FindAll(c context.Context, model FindAllModel) (response utils.Response)
- func (u *ArticleUseCaseImpl) Get(c context.Context, model GetModel) (response utils.Response)
- func (u *ArticleUseCaseImpl) Save(c context.Context, model SaveModel) utils.Response
- type CreateModel
- type DeleteModel
- type FindAllModel
- type GetModel
- type SaveModel
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func InjectUserId ¶
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 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 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 ¶
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)
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 FindAllModel ¶
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"` }