forked from easysoft/go-zentao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductplans.go
194 lines (170 loc) · 5.59 KB
/
productplans.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// Copyright 2022, ysicing
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package zentao
import (
"fmt"
"github.com/imroc/req/v3"
)
type ProductPlansService struct {
client *Client
}
type ProductPlanMeta struct {
Branch int `json:"branch,omitempty"`
Title string `json:"title"`
Parent int `json:"parent,omitempty"`
Desc string `json:"desc,omitempty"`
Begin string `json:"begin,omitempty"`
End string `json:"end,omitempty"`
}
type ProductPlanBody struct {
ID int `json:"id"`
Product int `json:"product"`
Order string `json:"order"`
Deleted bool `json:"deleted"`
ProductPlanMeta
}
type ProductPlanCreateMsg struct {
ProductPlanBody
Status string `json:"status"`
ClosedReason string `json:"closedReason"`
Stories []StoriesBody `json:"stories"`
Bugs []BugBody `json:"bugs"`
}
type ProductPlanListBody struct {
ProductPlanBody
Status string `json:"status,omitempty"`
ClosedReason string `json:"closedReason"`
Stories int `json:"stories"`
Bugs int `json:"bugs"`
Hour int `json:"hour"`
Project int `json:"project"`
ProjectID string `json:"projectID"`
Expired bool `json:"expired"`
}
type ProductPlanListMsg struct {
Page int `json:"page"`
Total int `json:"total"`
Limit int `json:"limit"`
Plans []ProductPlanListBody `json:"plans"`
}
type ProductPlanGetMsg struct {
ProductPlanBody
Stories []StoriesBody `json:"stories"`
Bugs []BugBody `json:"bugs"`
}
type ProductPlanUpdateMsg struct {
ProductPlanBody
Stories []StoriesBody `json:"stories"`
Bugs []BugBody `json:"bugs"`
}
type PlansStoriesIDs struct {
Stories []string `json:"stories"`
}
type PlansBugIDs struct {
Bugs []string `json:"bugs"`
}
type LinkStoriesMsg struct {
ProductPlanBody
Stories []StoriesBody `json:"stories"`
Bugs []BugBody `json:"bugs"`
}
// Create 创建产品计划
func (s *ProductPlansService) Create(id int, plan ProductPlanMeta) (*ProductPlanCreateMsg, *req.Response, error) {
var u ProductPlanCreateMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&plan).
SetResult(&u).
Post(s.client.RequestURL(fmt.Sprintf("/products/%d/plans", id)))
return &u, resp, err
}
// List 获取产品计划列表
func (s *ProductPlansService) List(id int) (*ProductPlanListMsg, *req.Response, error) {
var u ProductPlanListMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetResult(&u).
Get(s.client.RequestURL(fmt.Sprintf("/products/%d/plans", id)))
return &u, resp, err
}
// GetByID 获取计划详情
func (s *ProductPlansService) GetByID(id int) (*ProductPlanGetMsg, *req.Response, error) {
var u ProductPlanGetMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetResult(&u).
Get(s.client.RequestURL(fmt.Sprintf("/productplans/%d", id)))
return &u, resp, err
}
// UpdateByID 修改计划
func (s *ProductPlansService) UpdateByID(id int, plan ProductPlanMeta) (*ProductPlanUpdateMsg, *req.Response, error) {
var u ProductPlanUpdateMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&plan).
SetResult(&u).
Put(s.client.RequestURL(fmt.Sprintf("/productplans/%d", id)))
return &u, resp, err
}
// DeleteByID 删除计划
func (s *ProductPlansService) DeleteByID(id int) (*CustomResp, *req.Response, error) {
var u CustomResp
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetResult(&u).
Delete(s.client.RequestURL(fmt.Sprintf("/productplans/%d", id)))
return &u, resp, err
}
// LinkStories 产品计划关联需求
func (s *ProductPlansService) LinkStories(id int, story PlansStoriesIDs) (*LinkStoriesMsg, *req.Response, error) {
var u LinkStoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&story).
SetResult(&u).
Post(s.client.RequestURL(fmt.Sprintf("/productplans/%d/linkstories", id)))
return &u, resp, err
}
// LinkStories 产品计划关联需求
func (s *ProductPlansService) UnLinkStories(id int, story PlansStoriesIDs) (*LinkStoriesMsg, *req.Response, error) {
var u LinkStoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&story).
SetResult(&u).
Post(s.client.RequestURL(fmt.Sprintf("/productplans/%d/unlinkstories", id)))
return &u, resp, err
}
// LinkBugs 产品计划关联Bug
func (s *ProductPlansService) LinkBugs(id int, bug PlansBugIDs) (*LinkStoriesMsg, *req.Response, error) {
var u LinkStoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&bug).
SetResult(&u).
Post(s.client.RequestURL(fmt.Sprintf("/productplans/%d/linkBugs", id)))
return &u, resp, err
}
// UnLinkBugs 产品计划取消关联Bug
func (s *ProductPlansService) UnLinkBugs(id int, bug PlansBugIDs) (*LinkStoriesMsg, *req.Response, error) {
var u LinkStoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&bug).
SetResult(&u).
Post(s.client.RequestURL(fmt.Sprintf("/productplans/%d/unlinkbugs", id)))
return &u, resp, err
}