some changes ;]]]]]
This commit is contained in:
@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"fmt"
|
||||
"gitea-issue/giteaClient"
|
||||
"gitea-issue/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -9,11 +10,11 @@ import (
|
||||
"github.com/savaki/swag/swagger"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func PostIssue(c *gin.Context) {
|
||||
var issueProxy model.PostCreateIssueProxy
|
||||
|
||||
if err := c.BindJSON(&issueProxy); err != nil {
|
||||
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||
"message": "CREATE_ISSUE_ERROR",
|
||||
@ -22,6 +23,10 @@ func PostIssue(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
sudo := c.GetHeader("X-Sudo")
|
||||
if (sudo != "") {
|
||||
giteaClient.SudoUser(sudo)
|
||||
}
|
||||
giteaIssue, err := issueProxy.TransformToGiteaCreateIssueOption()
|
||||
if err != nil {
|
||||
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||
@ -39,16 +44,16 @@ func PostIssue(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, response)
|
||||
c.AsciiJSON(http.StatusOK, model.IssueTransformFromGitea(response))
|
||||
}
|
||||
|
||||
func PostIssueSwagger() (*swagger.Endpoint){
|
||||
func PostIssueSwagger() (*swagger.Endpoint) {
|
||||
return endpoint.New("post", "/issues", "Create issue",
|
||||
endpoint.Handler(PostIssue),
|
||||
endpoint.Description("Post new issue"),
|
||||
endpoint.Body(model.PostCreateIssueProxy{}, "Issue object", true),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, gitea.Issue{}, "Gitea Issue list"),
|
||||
endpoint.Response(http.StatusOK, model.GetCreateIssueProxy{}, "Gitea Issue list"),
|
||||
)
|
||||
}
|
||||
|
||||
@ -60,16 +65,17 @@ func GetIssues(c *gin.Context) {
|
||||
proxyIssues = append(proxyIssues, model.IssueTransformFromGitea(issue))
|
||||
}
|
||||
|
||||
if(err != nil){
|
||||
if (err != nil) {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, proxyIssues)
|
||||
}
|
||||
|
||||
func GetIssuesSwagger() (*swagger.Endpoint){
|
||||
func GetIssuesSwagger() (*swagger.Endpoint) {
|
||||
return endpoint.New("get", "/issues", "List project issues",
|
||||
endpoint.Handler(GetIssues),
|
||||
endpoint.Description("Get all issues"),
|
||||
endpoint.Security("token", "USER"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, []model.GetCreateIssueProxy{}, "Gitea Issue list"),
|
||||
)
|
||||
@ -85,13 +91,14 @@ func GetIssue(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, issue)
|
||||
c.AsciiJSON(http.StatusOK, model.IssueTransformFromGitea(issue))
|
||||
}
|
||||
|
||||
func GetIssueSwagger() (*swagger.Endpoint){
|
||||
return endpoint.New("get", "/issue/:id", "Get one issue",
|
||||
func GetIssueSwagger() (*swagger.Endpoint) {
|
||||
return endpoint.New("get", "/issues/:id", "Get one issue",
|
||||
endpoint.Handler(GetIssue),
|
||||
endpoint.Description("Get one issue"),
|
||||
endpoint.Security("token", "USER"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, model.GetCreateIssueProxy{}, "Gitea Issue"),
|
||||
)
|
||||
@ -104,17 +111,79 @@ func GetIssueComments(c *gin.Context) {
|
||||
c.AsciiJSON(http.StatusNotFound, err.Error())
|
||||
}
|
||||
issueComments, err := giteaClient.GetIssueComments(issueId)
|
||||
proxyComments := []model.GetCommentProxy{}
|
||||
|
||||
for _, comment := range issueComments {
|
||||
proxyComments = append(proxyComments, model.CommentTransformFromGitea(comment))
|
||||
}
|
||||
|
||||
if (err != nil) {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, proxyComments)
|
||||
|
||||
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),
|
||||
func GetIssueCommentsSwagger() (*swagger.Endpoint) {
|
||||
return endpoint.New("get", "/issues/:id/comments", "Get issue comments",
|
||||
endpoint.Handler(GetIssueComments),
|
||||
endpoint.Description("Get issue comments"),
|
||||
endpoint.Security("token", "USER"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, []gitea.Comment{}, "Gitea issue comments"),
|
||||
)
|
||||
}
|
||||
|
||||
func PostIssueComment(c *gin.Context) {
|
||||
var commentProxy model.PostCommentProxy
|
||||
|
||||
if err := c.BindJSON(&commentProxy); err != nil {
|
||||
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||
"message": "CREATE_COMMENT_ERROR",
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
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())
|
||||
}
|
||||
|
||||
giteaComment, err := commentProxy.TransformToGiteaComment()
|
||||
if err != nil {
|
||||
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||
"message": "CREATE_COMMENT_ERROR",
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
sudo := c.GetHeader("X-Sudo")
|
||||
if (sudo != "") {
|
||||
giteaClient.SudoUser(sudo)
|
||||
}
|
||||
response, err := giteaClient.CreateComment(issueId, giteaComment)
|
||||
if err != nil {
|
||||
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||
"message": "CREATE_ISSUE_ERROR",
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, model.CommentTransformFromGitea(response))
|
||||
}
|
||||
|
||||
func PostIssueCommentSwagger() (*swagger.Endpoint) {
|
||||
return endpoint.New("post", "/issues/:id/comments", "Create issue comment",
|
||||
endpoint.Handler(PostIssueComment),
|
||||
endpoint.Description("Add issue comment"),
|
||||
endpoint.Body(model.PostCommentProxy{}, "Comment object", true),
|
||||
endpoint.Security("token", "USER"),
|
||||
endpoint.Tags("issues"),
|
||||
endpoint.Response(http.StatusOK, model.GetCommentProxy{}, "Gitea issue comments"),
|
||||
)
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ func GetLabels(c *gin.Context) {
|
||||
c.AsciiJSON(http.StatusOK, labels)
|
||||
}
|
||||
|
||||
func GetLabelsSwagger() (*swagger.Endpoint){
|
||||
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"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
42
controller/user.go
Normal file
42
controller/user.go
Normal file
@ -0,0 +1,42 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitea-issue/giteaClient"
|
||||
"gitea-issue/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/savaki/swag/endpoint"
|
||||
"github.com/savaki/swag/swagger"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PostUser(c *gin.Context) {
|
||||
var userProxy model.PostUserProxy
|
||||
|
||||
if err := c.BindJSON(&userProxy); err != nil {
|
||||
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||
"message": "CREATE_USER_ERROR",
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
response, err := giteaClient.CreateUser(userProxy.TransformToGiteaUser())
|
||||
if err != nil {
|
||||
c.AsciiJSON(http.StatusUnprocessableEntity, gin.H{
|
||||
"message": "CREATE_USER_ERROR",
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.AsciiJSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func PostUserSwagger() (*swagger.Endpoint) {
|
||||
return endpoint.New("post", "/user", "Create user",
|
||||
endpoint.Handler(PostUser),
|
||||
endpoint.Description("Post new user"),
|
||||
endpoint.Body(model.PostUserProxy{}, "User object", true),
|
||||
endpoint.Tags("user"),
|
||||
endpoint.Response(http.StatusOK, gitea.User{}, "Gitea User"),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user