comm: swagger doc

This commit is contained in:
fallen-angle
2022-04-30 11:30:55 +08:00
parent 09b8e8e262
commit 2482141d0f
9 changed files with 538 additions and 128 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)
// SaveArticleHandler save an article
//SaveArticleHandler save an article
// @Tags Article
// @Accept json
// @Produce json
@@ -38,21 +38,27 @@ func SaveArticleHandler(c *gin.Context) {
utils.Succ(c, jsonMap)
}
// ListPublishedArticlesHandler get all article
//ListPublishedArticlesHandler get all article
// @Tags Article
// @Accept json
// @Produce json
// @Summary get all articles
// @Description Admin can get not published article
// @Success 200 {object} utils.GinResponse{data=[]models.BackArticle}
// @Success 200 {object} utils.GinResponse{data=[]models.ListArticle}
// @Router /article/list [get]
// @Param Token header string false "token"
func ListPublishedArticlesHandler(c *gin.Context) {
// TODO: admin need to show more articles
articles := article.ListPublishedArticles()
utils.Succ(c, articles)
}
//ListPublishedArticlesHandler get the user's article
// @Tags Article
// @Accept json
// @Produce json
// @Summary get user's articles
// @Success 200 {object} utils.GinResponse{data=[]models.BackArticle}
// @Router /article/list/{published} [get]
// @Param Token header string false "token"
// @Param published path string true "string enums" Enums(published, notpublished)
func ListArticlesByUser(c *gin.Context) {
published := c.Param("published")
claims := utils.ClaimsFromHeader(c)
@@ -72,7 +78,7 @@ func ListArticlesByUser(c *gin.Context) {
utils.Succ(c, articles)
}
// DeleteArticleHandler delete article
//DeleteArticleHandler delete article
// @Tags Article
// @Accept json
// @Produce json
@@ -99,15 +105,14 @@ func DeleteArticleHandler(c *gin.Context) {
utils.Succ(c, nil)
}
// GetArticleHandler get an article
//GetArticleHandler get an article
// @Tags Article
// @Accept json
// @Produce json
// @Summary get all articles
// @Summary get an articles
// @Description Admin can get not published article
// @Success 200 {object} utils.GinResponse{data=models.BackArticle}
// @Router /article/{id} [get]
// @Param Token header string false "token"
// @Param id path string true "id"
func GetArticleHandler(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
@@ -123,11 +128,11 @@ func GetArticleHandler(c *gin.Context) {
utils.Succ(c, res)
}
// PublishArticleHandler publish an article
//PublishArticleHandler publish an article
// @Tags Article
// @Accept json
// @Produce json
// @Summary get all articles
// @Summary publish an articles
// @Success 200 {object} utils.GinResponse{}
// @Router /article/{id}/publish [post]
// @Param Token header string true "token"