add swagger documentation
This commit is contained in:
73
controller/issue.go
Normal file
73
controller/issue.go
Normal file
@ -0,0 +1,73 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitea-issue/giteaClient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/savaki/swag/endpoint"
|
||||
"github.com/savaki/swag/swagger"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func GetIssues(c *gin.Context) {
|
||||
issues, err := giteaClient.GetIssues();
|
||||
if(err != nil){
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, issues)
|
||||
}
|
||||
|
||||
func GetIssuesSwagger() (*swagger.Endpoint){
|
||||
return endpoint.New("get", "/issues", "List project issues",
|
||||
endpoint.Handler(GetIssues),
|
||||
endpoint.Description("Get all issues"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, []gitea.Issue{}, "Gitea Issue list"),
|
||||
)
|
||||
}
|
||||
|
||||
func GetIssue(c *gin.Context) {
|
||||
issueId, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("ParseInt err: %+v", err))
|
||||
c.AsciiJSON(http.StatusNotFound, err.Error())
|
||||
}
|
||||
issue, err := giteaClient.GetIssue(issueId)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, issue)
|
||||
}
|
||||
|
||||
func GetIssueSwagger() (*swagger.Endpoint){
|
||||
return endpoint.New("get", "/issue/:id", "Get one issue",
|
||||
endpoint.Handler(GetIssue),
|
||||
endpoint.Description("Get one issue"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, gitea.Issue{}, "Gitea Issue"),
|
||||
)
|
||||
}
|
||||
|
||||
func GetIssueComments(c *gin.Context) {
|
||||
issueId, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("ParseInt err: %+v", err))
|
||||
c.AsciiJSON(http.StatusNotFound, err.Error())
|
||||
}
|
||||
issueComments, err := giteaClient.GetIssueComments(issueId)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, issueComments)
|
||||
}
|
||||
|
||||
func GetIssueCommentsSwagger() (*swagger.Endpoint){
|
||||
return endpoint.New("get", "/issue/:id/comments", "Get issue comments",
|
||||
endpoint.Handler(GetIssue),
|
||||
endpoint.Description("Get issue comments"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, []gitea.Comment{}, "Gitea issue comments"),
|
||||
)
|
||||
}
|
27
controller/label.go
Normal file
27
controller/label.go
Normal file
@ -0,0 +1,27 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitea-issue/giteaClient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/savaki/swag/endpoint"
|
||||
"github.com/savaki/swag/swagger"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetLabels(c *gin.Context) {
|
||||
labels, err := giteaClient.GetLabels()
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, labels)
|
||||
}
|
||||
|
||||
func GetLabelsSwagger() (*swagger.Endpoint){
|
||||
return endpoint.New("get", "/labels", "List project labels",
|
||||
endpoint.Handler(GetLabels),
|
||||
endpoint.Description("Get all labels"),
|
||||
endpoint.Tags("labels"),
|
||||
endpoint.Response(http.StatusOK, []gitea.Label{}, "Gitea labels list"),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user