create DTO for Issue
This commit is contained in:
parent
f2702297ba
commit
d4ade0ef0f
@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"gitea-issue/giteaClient"
|
"gitea-issue/giteaClient"
|
||||||
|
"gitea-issue/model"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/savaki/swag/endpoint"
|
"github.com/savaki/swag/endpoint"
|
||||||
"github.com/savaki/swag/swagger"
|
"github.com/savaki/swag/swagger"
|
||||||
@ -12,11 +13,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetIssues(c *gin.Context) {
|
func GetIssues(c *gin.Context) {
|
||||||
issues, err := giteaClient.GetIssues();
|
giteaIssues, err := giteaClient.GetIssues();
|
||||||
|
|
||||||
|
proxyIssues := []model.GetCreateIssueProxy{}
|
||||||
|
|
||||||
|
for _, issue := range giteaIssues {
|
||||||
|
proxyIssues = append(proxyIssues, model.TransformFromGitea(issue))
|
||||||
|
}
|
||||||
|
|
||||||
if(err != nil){
|
if(err != nil){
|
||||||
c.AbortWithStatus(http.StatusNotFound)
|
c.AbortWithStatus(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
c.AsciiJSON(http.StatusOK, issues)
|
c.AsciiJSON(http.StatusOK, proxyIssues)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetIssuesSwagger() (*swagger.Endpoint){
|
func GetIssuesSwagger() (*swagger.Endpoint){
|
||||||
@ -24,7 +32,7 @@ func GetIssuesSwagger() (*swagger.Endpoint){
|
|||||||
endpoint.Handler(GetIssues),
|
endpoint.Handler(GetIssues),
|
||||||
endpoint.Description("Get all issues"),
|
endpoint.Description("Get all issues"),
|
||||||
endpoint.Tags("issues"),
|
endpoint.Tags("issues"),
|
||||||
endpoint.Response(http.StatusOK, []gitea.Issue{}, "Gitea Issue list"),
|
endpoint.Response(http.StatusOK, []model.GetCreateIssueProxy{}, "Gitea Issue list"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +54,7 @@ func GetIssueSwagger() (*swagger.Endpoint){
|
|||||||
endpoint.Handler(GetIssue),
|
endpoint.Handler(GetIssue),
|
||||||
endpoint.Description("Get one issue"),
|
endpoint.Description("Get one issue"),
|
||||||
endpoint.Tags("issues"),
|
endpoint.Tags("issues"),
|
||||||
endpoint.Response(http.StatusOK, gitea.Issue{}, "Gitea Issue"),
|
endpoint.Response(http.StatusOK, model.GetCreateIssueProxy{}, "Gitea Issue"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package giteaClient
|
|
||||||
|
|
||||||
type GetCreateIssueProxy struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
Body string `json:"body"`
|
|
||||||
Assignee string `json:"assignee"`
|
|
||||||
Labels []int64 `json:"labels"`
|
|
||||||
Closed bool `json:"closed"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PostCreateIssueProxy struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
Body string `json:"body"`
|
|
||||||
Labels []int64 `json:"labels"`
|
|
||||||
}
|
|
||||||
|
|
52
model/createIssueProxy.go
Normal file
52
model/createIssueProxy.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"gitea-issue/giteaClient"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetCreateIssueProxy struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Labels []*gitea.Label `json:"labels"`
|
||||||
|
Closed *time.Time `json:"closed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PostCreateIssueProxy struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Labels []*gitea.Label `json:"labels"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateIssueOption, error){
|
||||||
|
giteaUser, err := giteaClient.GetUserInfo()
|
||||||
|
if( err != nil){
|
||||||
|
return gitea.CreateIssueOption{}, err;
|
||||||
|
}
|
||||||
|
labels := []int64{}
|
||||||
|
|
||||||
|
for _, label := range c.Labels{
|
||||||
|
labels = append(labels, label.ID)
|
||||||
|
}
|
||||||
|
giteaObject := gitea.CreateIssueOption{
|
||||||
|
Title: c.Title,
|
||||||
|
Body: c.Body,
|
||||||
|
Assignee: giteaUser.UserName,
|
||||||
|
Labels: labels,
|
||||||
|
Closed: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
return giteaObject, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) {
|
||||||
|
|
||||||
|
giteaIssue := GetCreateIssueProxy{
|
||||||
|
Title: issue.Title,
|
||||||
|
Body: issue.Body,
|
||||||
|
Labels: issue.Labels,
|
||||||
|
Closed: issue.Closed,
|
||||||
|
}
|
||||||
|
return giteaIssue
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user