-
Notifications
You must be signed in to change notification settings - Fork 7
/
organization.go
129 lines (100 loc) · 3.61 KB
/
organization.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
package zammad
import (
"fmt"
"net/http"
"net/url"
"time"
)
// Organization represent a Zammad organisation. See https://docs.zammad.org/en/latest/api/organization.html.
type Organization struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Shared bool `json:"shared"`
Domain string `json:"domain"`
DomainAssignment bool `json:"domain_assignment"`
Active bool `json:"active"`
Note string `json:"note"`
Vip bool `json:"vip"`
UpdatedByID int `json:"updated_by_id,omitempty"`
CreatedByID int `json:"created_by_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
MemberIds []int `json:"member_ids,omitempty"`
SecondaryMemberIds []int `json:"secondary_member_ids,omitempty"`
}
func (c *Client) OrganizationListResult(opts ...Option) *Result[Organization] {
return &Result[Organization]{
res: nil,
resFunc: c.OrganizationListWithOptions,
opts: NewRequestOptions(opts...),
}
}
func (c *Client) OrganizationList() ([]Organization, error) {
return c.OrganizationListResult().FetchAll()
}
func (c *Client) OrganizationListWithOptions(ro RequestOptions) ([]Organization, error) {
var organizations []Organization
req, err := c.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", c.Url, "/api/v1/organizations"), nil)
if err != nil {
return organizations, err
}
req.URL.RawQuery = ro.URLParams()
if err = c.sendWithAuth(req, &organizations); err != nil {
return organizations, err
}
return organizations, nil
}
func (c *Client) OrganizationSearch(query string, limit int) ([]Organization, error) {
var organizations []Organization
req, err := c.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", c.Url, fmt.Sprintf("/api/v1/organizations/search?query=%slimit=%d", url.QueryEscape(query), limit)), nil)
if err != nil {
return organizations, err
}
if err = c.sendWithAuth(req, &organizations); err != nil {
return organizations, err
}
return organizations, nil
}
func (c *Client) OrganizationShow(organizationID int) (Organization, error) {
var organization Organization
req, err := c.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", c.Url, fmt.Sprintf("/api/v1/organizations/%d", organizationID)), nil)
if err != nil {
return organization, err
}
if err = c.sendWithAuth(req, &organization); err != nil {
return organization, err
}
return organization, nil
}
func (c *Client) OrganizationCreate(o Organization) (Organization, error) {
var organization Organization
req, err := c.NewRequest(http.MethodPost, fmt.Sprintf("%s%s", c.Url, "/api/v1/organizations"), o)
if err != nil {
return organization, err
}
if err = c.sendWithAuth(req, &organization); err != nil {
return organization, err
}
return organization, nil
}
func (c *Client) OrganizationUpdate(organizationID int, o Organization) (Organization, error) {
var organization Organization
req, err := c.NewRequest(http.MethodPut, fmt.Sprintf("%s%s", c.Url, fmt.Sprintf("/api/v1/organizations/%d", organizationID)), o)
if err != nil {
return organization, err
}
if err = c.sendWithAuth(req, &organization); err != nil {
return organization, err
}
return organization, nil
}
func (c *Client) OrganizationDelete(organizationID int) error {
req, err := c.NewRequest(http.MethodDelete, fmt.Sprintf("%s%s", c.Url, fmt.Sprintf("/api/v1/organizations/%d", organizationID)), nil)
if err != nil {
return err
}
if err = c.sendWithAuth(req, nil); err != nil {
return err
}
return nil
}