-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
39 lines (32 loc) · 1.03 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
package client
import (
"context"
)
func (c *Client) groupCrudOpts() crudOptions {
return crudOptions{
base: "api/groups/",
newRequest: c.newRequest,
getID: func(v any) int64 {
return v.(Group).ID
},
setPage: func(opts any, page *PageToken) {
opts.(*ListGroupsOptions).Page = page
},
}
}
type ListGroupsOptions struct {
ListOptions
Ordering OrderingSpec `url:"ordering"`
Name CharFilterSpec `url:"name"`
}
func (c *Client) ListGroups(ctx context.Context, opts ListGroupsOptions) ([]Group, *Response, error) {
return crudList[Group](ctx, c.groupCrudOpts(), opts)
}
// ListAllGroups iterates over all groups matching the filters specified in opts,
// invoking handler for each.
func (c *Client) ListAllGroups(ctx context.Context, opts ListGroupsOptions, handler func(context.Context, Group) error) error {
return crudListAll[Group](ctx, c.groupCrudOpts(), opts, handler)
}
func (c *Client) GetGroup(ctx context.Context, id int64) (*Group, *Response, error) {
return crudGet[Group](ctx, c.groupCrudOpts(), id)
}