-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathteam.go
More file actions
241 lines (198 loc) · 6.56 KB
/
team.go
File metadata and controls
241 lines (198 loc) · 6.56 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package backlog
import (
"context"
"fmt"
"io"
)
// Team : team
type Team struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Members []*User `json:"members,omitempty"`
DisplayOrder *int `json:"displayOrder,omitempty"`
CreatedUser *User `json:"createdUser,omitempty"`
Created *Timestamp `json:"created,omitempty"`
UpdatedUser *User `json:"updatedUser,omitempty"`
Updated *Timestamp `json:"updated,omitempty"`
}
// GetTeams returns the list of teams
func (c *Client) GetTeams(opts *GetTeamsOptions) ([]*Team, error) {
return c.GetTeamsContext(context.Background(), opts)
}
// GetTeamsContext returns the list of teams with context
func (c *Client) GetTeamsContext(ctx context.Context, opts *GetTeamsOptions) ([]*Team, error) {
u, err := c.AddOptions("/api/v2/teams", opts)
if err != nil {
return nil, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
var teams []*Team
if err := c.Do(ctx, req, &teams); err != nil {
return nil, err
}
return teams, nil
}
// CreateTeam creates a team
// a space backlog.com cannot use this API
func (c *Client) CreateTeam(input *CreateTeamInput) (*Team, error) {
return c.CreateTeamContext(context.Background(), input)
}
// CreateTeamContext creates a team with Context
// a space backlog.com cannot use this API
func (c *Client) CreateTeamContext(ctx context.Context, input *CreateTeamInput) (*Team, error) {
u := "/api/v2/teams"
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
team := new(Team)
if err := c.Do(ctx, req, &team); err != nil {
return nil, err
}
return team, nil
}
// GetTeam returns a teams
func (c *Client) GetTeam(teamID int) (*Team, error) {
return c.GetTeamContext(context.Background(), teamID)
}
// GetTeamContext returns a team with context
func (c *Client) GetTeamContext(ctx context.Context, teamID int) (*Team, error) {
u := fmt.Sprintf("/api/v2/teams/%v", teamID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
var team *Team
if err := c.Do(ctx, req, &team); err != nil {
return nil, err
}
return team, nil
}
// UpdateTeam updates a team
func (c *Client) UpdateTeam(teamID int, input *UpdateTeamInput) (*Team, error) {
return c.UpdateTeamContext(context.Background(), teamID, input)
}
// UpdateTeamContext updates a team with Context
func (c *Client) UpdateTeamContext(ctx context.Context, teamID int, input *UpdateTeamInput) (*Team, error) {
u := fmt.Sprintf("/api/v2/teams/%v", teamID)
req, err := c.NewRequest("PATCH", u, input)
if err != nil {
return nil, err
}
team := new(Team)
if err := c.Do(ctx, req, &team); err != nil {
return nil, err
}
return team, nil
}
// DeleteTeam deletes a team
func (c *Client) DeleteTeam(teamID int) (*Team, error) {
return c.DeleteTeamContext(context.Background(), teamID)
}
// DeleteTeamContext deletes a team with Context
func (c *Client) DeleteTeamContext(ctx context.Context, teamID int) (*Team, error) {
u := fmt.Sprintf("/api/v2/teams/%v", teamID)
req, err := c.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
team := new(Team)
if err := c.Do(ctx, req, &team); err != nil {
return nil, err
}
return team, nil
}
// GetTeamIcon downloads team icon
func (c *Client) GetTeamIcon(teamID int, writer io.Writer) error {
return c.GetTeamIconContext(context.Background(), teamID, writer)
}
// GetTeamIconContext downloads team icon with context
func (c *Client) GetTeamIconContext(ctx context.Context, teamID int, writer io.Writer) error {
u := fmt.Sprintf("/api/v2/teams/%v/icon", teamID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return err
}
if err := c.Do(ctx, req, writer); err != nil {
return err
}
return nil
}
// GetProjectTeams returns the list of teams in a project
func (c *Client) GetProjectTeams(projectIDOrKey interface{}) ([]*Team, error) {
return c.GetProjectTeamsContext(context.Background(), projectIDOrKey)
}
// GetProjectTeamsContext returns the list of teams in a project with context
func (c *Client) GetProjectTeamsContext(ctx context.Context, projectIDOrKey interface{}) ([]*Team, error) {
u := fmt.Sprintf("/api/v2/projects/%v/teams", projectIDOrKey)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
var teams []*Team
if err := c.Do(ctx, req, &teams); err != nil {
return nil, err
}
return teams, nil
}
// AddProjectTeam adds a team to a project
func (c *Client) AddProjectTeam(projectIDOrKey interface{}, input *AddProjectTeamInput) (*Team, error) {
return c.AddProjectTeamContext(context.Background(), projectIDOrKey, input)
}
// AddProjectTeamContext adds a team to a project with context
func (c *Client) AddProjectTeamContext(ctx context.Context, projectIDOrKey interface{}, input *AddProjectTeamInput) (*Team, error) {
u := fmt.Sprintf("/api/v2/projects/%v/teams", projectIDOrKey)
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
team := new(Team)
if err := c.Do(ctx, req, &team); err != nil {
return nil, err
}
return team, nil
}
// DeleteProjectTeam deletes a team to a project
func (c *Client) DeleteProjectTeam(projectIDOrKey interface{}, input *DeleteProjectTeamInput) (*Team, error) {
return c.DeleteProjectTeamContext(context.Background(), projectIDOrKey, input)
}
// DeleteProjectTeamContext deletes a team to a project with context
func (c *Client) DeleteProjectTeamContext(ctx context.Context, projectIDOrKey interface{}, input *DeleteProjectTeamInput) (*Team, error) {
u := fmt.Sprintf("/api/v2/projects/%v/teams", projectIDOrKey)
req, err := c.NewRequest("DELETE", u, input)
if err != nil {
return nil, err
}
team := new(Team)
if err := c.Do(ctx, req, &team); err != nil {
return nil, err
}
return team, nil
}
// GetTeamsOptions specifies parameters to the GetTeams method.
type GetTeamsOptions struct {
Order Order `url:"order,omitempty"`
Offset *int `url:"offset,omitempty"`
Count *int `url:"count,omitempty"`
}
// CreateTeamInput specifies parameters to the CreateTeam method.
type CreateTeamInput struct {
Name *string `json:"name"`
Members []int `json:"members,omitempty"`
}
// UpdateTeamInput specifies parameters to the UpdateTeam method.
type UpdateTeamInput struct {
Name *string `json:"name"`
Members []int `json:"members,omitempty"`
}
// AddProjectTeamInput specifies parameters to the AddProjectTeam method.
type AddProjectTeamInput struct {
TeamID *int `json:"teamId"`
}
// DeleteProjectTeamInput specifies parameters to the DeleteProjectTeam method.
type DeleteProjectTeamInput struct {
TeamID *int `json:"teamId"`
}