-
Notifications
You must be signed in to change notification settings - Fork 2
/
group.go
101 lines (84 loc) · 3.56 KB
/
group.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
package buddy
import (
"net/http"
)
const (
GroupMemberStatusManager = "MANAGER"
GroupMemberStatusMember = "MEMBER"
)
type GroupService struct {
client *Client
}
type Group struct {
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
AutoAssignToNewProjects bool `json:"auto_assign_to_new_projects"`
AutoAssignPermissionSetId int `json:"auto_assign_permission_set_id"`
}
type Groups struct {
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
Groups []*Group `json:"groups"`
}
type GroupOps struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
AutoAssignToNewProjects *bool `json:"auto_assign_to_new_projects,omitempty"`
AutoAssignPermissionSetId *int `json:"auto_assign_permission_set_id,omitempty"`
}
type GroupMemberOps struct {
Id *int `json:"id,omitempty"`
Status *string `json:"status,omitempty"`
}
func (s *GroupService) Get(domain string, groupId int) (*Group, *http.Response, error) {
var g *Group
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/groups/%d", domain, groupId), &g, nil)
return g, resp, err
}
func (s *GroupService) GetList(domain string) (*Groups, *http.Response, error) {
var l *Groups
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/groups", domain), &l, nil)
return l, resp, err
}
func (s *GroupService) Create(domain string, ops *GroupOps) (*Group, *http.Response, error) {
var g *Group
resp, err := s.client.Create(s.client.NewUrlPath("/workspaces/%s/groups", domain), &ops, nil, &g)
return g, resp, err
}
func (s *GroupService) Update(domain string, groupId int, ops *GroupOps) (*Group, *http.Response, error) {
var g *Group
resp, err := s.client.Patch(s.client.NewUrlPath("/workspaces/%s/groups/%d", domain, groupId), &ops, nil, &g)
return g, resp, err
}
func (s *GroupService) Delete(domain string, groupId int) (*http.Response, error) {
return s.client.Delete(s.client.NewUrlPath("/workspaces/%s/groups/%d", domain, groupId), nil, nil)
}
func (s *GroupService) AddGroupMember(domain string, groupId int, ops *GroupMemberOps) (*Member, *http.Response, error) {
var m *Member
resp, err := s.client.Create(s.client.NewUrlPath("/workspaces/%s/groups/%d/members", domain, groupId), &ops, nil, &m)
return m, resp, err
}
func (s *GroupService) DeleteGroupMember(domain string, groupId int, memberId int) (*http.Response, error) {
return s.client.Delete(s.client.NewUrlPath("/workspaces/%s/groups/%d/members/%d", domain, groupId, memberId), nil, nil)
}
func (s *GroupService) UpdateGroupMember(domain string, groupId int, memberId int, status string) (*Member, *http.Response, error) {
var m *Member
ops := GroupMemberOps{
Status: &status,
}
resp, err := s.client.Patch(s.client.NewUrlPath("/workspaces/%s/groups/%d/members/%d", domain, groupId, memberId), &ops, nil, &m)
return m, resp, err
}
func (s *GroupService) GetGroupMember(domain string, groupId int, memberId int) (*Member, *http.Response, error) {
var m *Member
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/groups/%d/members/%d", domain, groupId, memberId), &m, nil)
return m, resp, err
}
func (s *GroupService) GetGroupMembers(domain string, groupId int) (*Members, *http.Response, error) {
var l *Members
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/groups/%d/members", domain, groupId), &l, nil)
return l, resp, err
}