-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathorganizations.go
More file actions
117 lines (102 loc) · 3.15 KB
/
organizations.go
File metadata and controls
117 lines (102 loc) · 3.15 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
package client
import (
"context"
"github.com/uselagoon/machinery/api/schema"
)
// OrganizationByID queries the Lagoon API for an organization by its ID, and
// unmarshals the response into organization.
func (c *Client) OrganizationByID(ctx context.Context, id uint, organization *schema.Organization) error {
req, err := c.newRequest("_lgraphql/organizations/organizationById.graphql",
map[string]interface{}{
"id": id,
})
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"organizationById"`
}{
Response: organization,
})
}
// OrganizationByName queries the Lagoon API for an organization by its name, and
// unmarshals the response into organization.
func (c *Client) OrganizationByName(ctx context.Context, name string, organization *schema.Organization) error {
req, err := c.newRequest("_lgraphql/organizations/organizationByName.graphql",
map[string]interface{}{
"name": name,
})
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"organizationByName"`
}{
Response: organization,
})
}
// AddOrganization adds an organization.
func (c *Client) AddOrganization(
ctx context.Context, in *schema.AddOrganizationInput, org *schema.Organization) error {
req, err := c.newRequest("_lgraphql/organizations/addOrganization.graphql", in)
if err != nil {
return err
}
return wrapErr(c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"addOrganization"`
}{
Response: org,
}))
}
// DeleteOrganization deletes an organization.
func (c *Client) DeleteOrg(ctx context.Context,
id uint, out *schema.DeleteOrganizationInput) error {
req, err := c.newRequest("_lgraphql/organizations/deleteOrganization.graphql",
map[string]interface{}{
"id": id,
})
if err != nil {
return err
}
return c.client.Run(ctx, req, &out)
}
// UpdateOrganization updates an organization.
func (c *Client) UpdateOrganization(
ctx context.Context, id uint, patch schema.UpdateOrganizationPatchInput, organization *schema.Organization) error {
req, err := c.newRequest("_lgraphql/organizations/updateOrganization.graphql",
map[string]interface{}{
"id": id,
"patch": patch,
})
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"updateOrganization"`
}{
Response: organization,
})
}
// AllOrganizations queries the Lagoon API for all organizations.
func (c *Client) AllOrganizations(ctx context.Context, organizations *[]schema.Organization) error {
req, err := c.newRequest("_lgraphql/organizations/allOrganizations.graphql", nil)
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *[]schema.Organization `json:"allOrganizations"`
}{
Response: organizations,
})
}
func (c *Client) AllOrganizationsExtended(ctx context.Context, organizations *[]schema.Organization) error {
req, err := c.newRequest("_lgraphql/organizations/allOrganizationsWithProjects.graphql", nil)
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *[]schema.Organization `json:"allOrganizations"`
}{
Response: organizations,
})
}