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"

View File

@@ -15,7 +15,7 @@ import (
// @Accept json
// @Produce json
// @Summary user register account
// @Success 200 {object} utils.GinResponse{}
// @Success 200 {object} utils.GinResponse{data=models.BackUser}
// @Router /user/register [post]
// @Param json body models.UserRegister true "json"
func UserRegisterHandler(c *gin.Context) {
@@ -72,7 +72,9 @@ func UserLoginHandler(c *gin.Context) {
}
token := user.Login(jsonMap)
if token == "" {
// TODO: change to request error
// Login failed reasons as follow:
// 1. account or password incorrect
// 2. account apply not pass
utils.Succ(c, map[string]interface{}{"msg": "failed"})
return
}
@@ -87,6 +89,7 @@ func UserLoginHandler(c *gin.Context) {
// @Success 200 {object} utils.GinResponse{}
// @Router /user/registers/{approved} [get]
// @Param Token header string true "token"
// @Param approved path string true "string enums" Enums(approved, notapproved)
func ListRegisterUserHandler(c *gin.Context) {
approved := c.Param("approved")
claims := utils.ClaimsFromHeader(c)
@@ -111,7 +114,7 @@ func ListRegisterUserHandler(c *gin.Context) {
// @Produce json
// @Summary send verify code
// @Success 200 {object} utils.GinResponse{}
// @Router /user/{code} [get]
// @Router /user/code/{email} [get]
// @Param email path string true "email"
func SendEmailCodeHandler(c *gin.Context) {
email := c.Param("email")