create issue endpoint

This commit is contained in:
Aleksander Cynarski 2019-12-04 22:37:18 +01:00
parent d4ade0ef0f
commit f24c030d8f
Signed by: paramah
GPG Key ID: C4340BA42B9C173A
5 changed files with 51 additions and 5 deletions

View File

@ -12,13 +12,52 @@ import (
"fmt" "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",
"error": err.Error(),
})
return
}
giteaIssue, err := issueProxy.TransformToGiteaCreateIssueOption()
if err != nil {
c.AsciiJSON(http.StatusBadRequest, gin.H{
"message": "CREATE_ISSUE_ERROR",
"error": err.Error(),
})
return
}
response, err := giteaClient.CreateIssue(giteaIssue)
if err != nil {
c.AsciiJSON(http.StatusBadRequest, gin.H{
"message": "CREATE_ISSUE_ERROR",
"error": err.Error(),
})
return
}
c.AsciiJSON(http.StatusOK, response)
}
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"),
)
}
func GetIssues(c *gin.Context) { func GetIssues(c *gin.Context) {
giteaIssues, err := giteaClient.GetIssues(); giteaIssues, err := giteaClient.GetIssues();
proxyIssues := []model.GetCreateIssueProxy{} proxyIssues := []model.GetCreateIssueProxy{}
for _, issue := range giteaIssues { for _, issue := range giteaIssues {
proxyIssues = append(proxyIssues, model.TransformFromGitea(issue)) proxyIssues = append(proxyIssues, model.IssueTransformFromGitea(issue))
} }
if(err != nil){ if(err != nil){

View File

@ -73,6 +73,11 @@ func GetLabels() ([]*gitea.Label, error) {
return giteaLabels, nil return giteaLabels, nil
} }
func CreateIssue(issue gitea.Issue){ func CreateIssue(issue gitea.CreateIssueOption) (*gitea.Issue, error){
giteaCreateIssue, err := giteaClient.CreateIssue(giteaOwner, giteaRepo, issue)
if( err != nil){
fmt.Println(fmt.Sprintf("Gitea get labels error: %+v", err.Error()))
return nil, err
}
return giteaCreateIssue, nil
} }

View File

@ -62,6 +62,7 @@ func main() {
swag.Tag("issues", "Gitea issues proxy endpoints"), swag.Tag("issues", "Gitea issues proxy endpoints"),
swag.Tag("labels", "Gites labels for issue"), swag.Tag("labels", "Gites labels for issue"),
swag.Endpoints( swag.Endpoints(
controller.PostIssueSwagger(),
controller.GetIssuesSwagger(), controller.GetIssuesSwagger(),
controller.GetIssueSwagger(), controller.GetIssueSwagger(),
controller.GetIssueCommentsSwagger(), controller.GetIssueCommentsSwagger(),

View File

@ -40,7 +40,7 @@ func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateI
return giteaObject, nil return giteaObject, nil
} }
func TransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) { func IssueTransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) {
giteaIssue := GetCreateIssueProxy{ giteaIssue := GetCreateIssueProxy{
Title: issue.Title, Title: issue.Title,

1
model/labelProxy.go Normal file
View File

@ -0,0 +1 @@
package model