create DTO for Issue
This commit is contained in:
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
|
||||
}
|
Reference in New Issue
Block a user