Skip to content

Commit

Permalink
* [project] imp project api
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Sep 20, 2024
1 parent 739d49f commit 22bd651
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 81 deletions.
48 changes: 23 additions & 25 deletions example/projects/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,38 @@ func main() {
zentao.WithoutProxy(),
)
if err != nil {
log.Fatal(err)
panic(err)
}
pds, _, err := zt.Products.List()
p1, _, err := zt.Projects.List("100", "1")
if err != nil {
panic(err)
}
id := 0
if len(pds.Products) == 0 {
pd, _, err := zt.Products.Create(zentao.ProductsMeta{
Name: fmt.Sprintf("abc%d%d", time.Now().Minute(), time.Now().Second()),
Code: fmt.Sprintf("abc%d%d", time.Now().Minute(), time.Now().Second()),
})
if err != nil {
panic(err)
}
id = pd.ID
} else {
id = pds.Products[0].ID
log.Printf("projects count: %v", len(p1.Projects))
p2, _, err := zt.Projects.Create(zentao.ProjectsCreateMeta{
Name: fmt.Sprintf("gosdk_p1_%s", time.Now().Format("20060102150405")),
Code: fmt.Sprintf("gosdk_p1_%s", time.Now().Format("20060102150405")),
Begin: time.Now().Format("2006-01-02"),
End: time.Now().AddDate(0, 0, 7).Format("2006-01-02"),
Products: []int{1},
})
if err != nil {
panic(err)
}
pjs, _, err := zt.Projects.List("100", "1")
log.Printf("created project: %v", p2.ID)
p3, _, err := zt.Projects.GetByID(p2.ID)
if err != nil {
log.Fatal(err)
panic(err)
}
log.Printf("Projects count: %v", len(pjs.Projects))
pj, _, err := zt.Projects.Create(zentao.ProjectsCreateMeta{
Name: fmt.Sprintf("abc%d%d", time.Now().Minute(), time.Now().Second()),
Code: fmt.Sprintf("abc%d%d", time.Now().Minute(), time.Now().Second()),
Begin: time.Now().Format("2006-01-02"),
End: time.Now().Add(72 * time.Hour).Format("2006-01-02"),
Products: []int{id},
Parent: 0,
log.Printf("get project: %v", p3.ID)
p4, _, err := zt.Projects.UpdateByID(p2.ID, zentao.ProjectsUpdateMeta{
Name: fmt.Sprintf("gosdk_p4_%s", time.Now().Format("20060102150405")),
})
if err != nil {
panic(err)
}
log.Printf("Create Projects: %v", pj.ID)
log.Printf("updated project: %v", p4.ID)
_, _, err = zt.Projects.DeleteByID(p2.ID)
if err != nil {
panic(err)
}
}
132 changes: 76 additions & 56 deletions zentao/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package zentao

import (
"fmt"
"time"

"github.com/imroc/req/v3"
)
Expand All @@ -38,58 +37,76 @@ type ProjectsCreateMeta struct {
}

type ProjectsBody struct {
ID int `json:"id"`
Name string `json:"name"`
Code string `json:"code"`
Model string `json:"model"`
Type string `json:"type"`
Budget string `json:"budget"`
Budgetunit string `json:"budgetUnit"`
Parent int `json:"parent"`
Begin string `json:"begin"`
End string `json:"end"`
Status string `json:"status"`
Openedby UserMeta `json:"openedBy"`
Openeddate time.Time `json:"openedDate"`
Pm UserMeta `json:"PM"`
Progress int `json:"progress,omitempty"`
}

type ProjectsCreateMsg struct {
ProjectsBody
ID int `json:"id"`
Project int `json:"project"`
Charter int `json:"charter"`
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Model string `json:"model"`
Type string `json:"type"`
Category string `json:"category"`
Budget string `json:"budget"`
Budgetunit string `json:"budgetUnit"`
Parent int `json:"parent"`
Begin string `json:"begin"`
End string `json:"end"`
Status string `json:"status"`
SubStatus string `json:"subStatus"`
Openedby any `json:"openedBy"`
Openeddate string `json:"openedDate"`
Pm any `json:"PM"`
Po any `json:"PO"`
Qd any `json:"QD"`
Rd any `json:"RD"`
Progress any `json:"progress,omitempty"`
Auth ProjectAuth `json:"auth"`
StoryType string `json:"storyType"`
HasProduct int `json:"hasProduct"`
Days int `json:"days"`
Pri string `json:"pri"`
Desc string `json:"desc"`
Estimate any `json:"estimate"` // 列表是字符串, 其他是float64
Left int `json:"left"`
Consumed int `json:"consumed"`
TeamCount int `json:"teamCount"`
LastEditedBy any `json:"lastEditedBy"`
LastEditedDate string `json:"lastEditedDate"`
ClosedBy any `json:"closedBy"`
ClosedDate string `json:"closedDate"`
ClosedReason string `json:"closedReason"`
CanceledBy any `json:"canceledBy"`
CanceledDate string `json:"canceledDate"`
SuspendedDate string `json:"suspendedDate"`
Team string `json:"team"`
Acl ACL `json:"acl"`
Whitelist any `json:"whitelist"`
Vision string `json:"vision"`
Deleted bool `json:"deleted"`
TeamMembers any `json:"teamMembers"`
LeftTasks string `json:"leftTasks"`
StatusTitle string `json:"statusTitle"`
Consume string `json:"consume"`
Surplus string `json:"surplus"`
Invested float64 `json:"invested"`
StoryCount int `json:"storyCount"`
StoryPoints string `json:"storyPoints"`
ExecutionCount int `json:"executionCount"`
From string `json:"from"`
Actions []string `json:"actions"`
Version int `json:"version"`
Parentversion int `json:"parentVersion"`
Order int `json:"order"`
Lifetime string `json:"lifetime"`
Attribute string `json:"attribute"`
Percent int `json:"percent"`
Milestone string `json:"milestone"`
Output string `json:"output"`
Auth string `json:"auth"`
Path string `json:"path"`
Grade int `json:"grade"`
Realbegan string `json:"realBegan"`
Realend string `json:"realEnd"`
Days int `json:"days"`
Substatus string `json:"subStatus"`
Pri string `json:"pri"`
Desc string `json:"desc"`
Version int `json:"version"`
Parentversion int `json:"parentVersion"`
Planduration int `json:"planDuration"`
Realduration int `json:"realDuration"`
Openedversion string `json:"openedVersion"`
Lasteditedby UserMeta `json:"lastEditedBy"`
Lastediteddate time.Time `json:"lastEditedDate"`
Closedby UserMeta `json:"closedBy"`
Closeddate time.Time `json:"closedDate"`
Canceledby UserMeta `json:"canceledBy"`
Canceleddate time.Time `json:"canceledDate"`
Po interface{} `json:"PO"`
Qd interface{} `json:"QD"`
Rd interface{} `json:"RD"`
Team string `json:"team"`
ACL string `json:"acl"`
Whitelist []UserMeta `json:"whitelist"`
Order int `json:"order"`
Deleted bool `json:"deleted"`
}

type ProjectsListMsg struct {
Expand All @@ -100,14 +117,17 @@ type ProjectsListMsg struct {
}

type ProjectsUpdateMeta struct {
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Parent int `json:"parent,omitempty"`
Days int `json:"days,omitempty"`
Desc string `json:"desc,omitempty"`
ACL string `json:"acl,omitempty"`
Auth string `json:"auth,omitempty"`
Whitelist []string `json:"whitelist,omitempty"`
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Parent int `json:"parent,omitempty"`
Budget int `json:"budget,omitempty"`
BudgetUnit string `json:"budgetUnit,omitempty"`
PM int `json:"PM,omitempty"`
Days int `json:"days,omitempty"`
Desc string `json:"desc,omitempty"`
ACL ACL `json:"acl,omitempty"`
Auth ProjectAuth `json:"auth,omitempty"`
Whitelist any `json:"whitelist,omitempty"`
}

// List 获取项目列表
Expand All @@ -125,8 +145,8 @@ func (s *ProjectsService) List(limit, page string) (*ProjectsListMsg, *req.Respo
}

// Create 创建项目
func (s *ProjectsService) Create(program ProjectsCreateMeta) (*ProjectsCreateMsg, *req.Response, error) {
var u ProjectsCreateMsg
func (s *ProjectsService) Create(program ProjectsCreateMeta) (*ProjectsBody, *req.Response, error) {
var u ProjectsBody
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&program).
Expand All @@ -146,8 +166,8 @@ func (s *ProjectsService) DeleteByID(id int) (*CustomResp, *req.Response, error)
}

// UpdateByID 修改项目
func (s *ProjectsService) UpdateByID(id int, pum ProjectsUpdateMeta) (*ProjectsCreateMsg, *req.Response, error) {
var u ProjectsCreateMsg
func (s *ProjectsService) UpdateByID(id int, pum ProjectsUpdateMeta) (*ProjectsBody, *req.Response, error) {
var u ProjectsBody
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&pum).
Expand All @@ -157,8 +177,8 @@ func (s *ProjectsService) UpdateByID(id int, pum ProjectsUpdateMeta) (*ProjectsC
}

// GetByID 获取项目详情
func (s *ProjectsService) GetByID(id int) (*ProjectsCreateMsg, *req.Response, error) {
var u ProjectsCreateMsg
func (s *ProjectsService) GetByID(id int) (*ProjectsBody, *req.Response, error) {
var u ProjectsBody
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetSuccessResult(&u).
Expand Down
7 changes: 7 additions & 0 deletions zentao/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ var (
ReviewResultClarify StoriesReviewResult = "clarify" // 有待明确
)

type ProjectAuth string // 项目权限

var (
ProjectExtend ProjectAuth = "extend" // 继承
ProjectReset ProjectAuth = "reset" // 重新定义
)

// CustomResp 通用Resp
type CustomResp struct {
Message string `json:"message,omitempty"`
Expand Down

0 comments on commit 22bd651

Please sign in to comment.