-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
56 lines (45 loc) · 1.61 KB
/
tag.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
package client
import (
"context"
)
func (c *Client) tagCrudOpts() crudOptions {
return crudOptions{
base: "api/tags/",
newRequest: c.newRequest,
getID: func(v any) int64 {
return v.(Tag).ID
},
setPage: func(opts any, page *PageToken) {
opts.(*ListTagsOptions).Page = page
},
}
}
type ListTagsOptions struct {
ListOptions
Ordering OrderingSpec `url:"ordering"`
Owner IntFilterSpec `url:"owner"`
Name CharFilterSpec `url:"name"`
}
func (c *Client) ListTags(ctx context.Context, opts ListTagsOptions) ([]Tag, *Response, error) {
return crudList[Tag](ctx, c.tagCrudOpts(), opts)
}
// ListAllTags iterates over all tags matching the filters specified in opts,
// invoking handler for each.
func (c *Client) ListAllTags(ctx context.Context, opts ListTagsOptions, handler func(context.Context, Tag) error) error {
return crudListAll[Tag](ctx, c.tagCrudOpts(), opts, handler)
}
func (c *Client) GetTag(ctx context.Context, id int64) (*Tag, *Response, error) {
return crudGet[Tag](ctx, c.tagCrudOpts(), id)
}
func (c *Client) CreateTag(ctx context.Context, data *TagFields) (*Tag, *Response, error) {
return crudCreate[Tag](ctx, c.tagCrudOpts(), data)
}
func (c *Client) UpdateTag(ctx context.Context, id int64, data *Tag) (*Tag, *Response, error) {
return crudUpdate[Tag](ctx, c.tagCrudOpts(), id, data)
}
func (c *Client) PatchTag(ctx context.Context, id int64, data *TagFields) (*Tag, *Response, error) {
return crudPatch[Tag](ctx, c.tagCrudOpts(), id, data)
}
func (c *Client) DeleteTag(ctx context.Context, id int64) (*Response, error) {
return crudDelete[Tag](ctx, c.tagCrudOpts(), id)
}