-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcategory.go
107 lines (87 loc) · 3.24 KB
/
category.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
package backlog
import (
"context"
"fmt"
)
// Category : category
type Category struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
DisplayOrder *int `json:"displayOrder,omitempty"`
}
// GetCategories returns the list of categories
func (c *Client) GetCategories(projectIDOrKey interface{}) ([]*Category, error) {
return c.GetCategoriesContext(context.Background(), projectIDOrKey)
}
// GetCategoriesContext returns the list of categories with context
func (c *Client) GetCategoriesContext(ctx context.Context, projectIDOrKey interface{}) ([]*Category, error) {
u := fmt.Sprintf("/api/v2/projects/%v/categories", projectIDOrKey)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
categories := []*Category{}
if err := c.Do(ctx, req, &categories); err != nil {
return nil, err
}
return categories, nil
}
// CreateCategory creates a category
func (c *Client) CreateCategory(projectIDOrKey interface{}, input *CreateCategoryInput) (*Category, error) {
return c.CreateCategoryContext(context.Background(), projectIDOrKey, input)
}
// CreateCategoryContext creates a category with Context
func (c *Client) CreateCategoryContext(ctx context.Context, projectIDOrKey interface{}, input *CreateCategoryInput) (*Category, error) {
u := fmt.Sprintf("/api/v2/projects/%v/categories", projectIDOrKey)
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
category := new(Category)
if err := c.Do(ctx, req, &category); err != nil {
return nil, err
}
return category, nil
}
// UpdateCategory updates a category
func (c *Client) UpdateCategory(projectIDOrKey interface{}, categoryID int, input *UpdateCategoryInput) (*Category, error) {
return c.UpdateCategoryContext(context.Background(), projectIDOrKey, categoryID, input)
}
// UpdateCategoryContext updates a category with Context
func (c *Client) UpdateCategoryContext(ctx context.Context, projectIDOrKey interface{}, categoryID int, input *UpdateCategoryInput) (*Category, error) {
u := fmt.Sprintf("/api/v2/projects/%v/categories/%v", projectIDOrKey, categoryID)
req, err := c.NewRequest("PATCH", u, input)
if err != nil {
return nil, err
}
category := new(Category)
if err := c.Do(ctx, req, &category); err != nil {
return nil, err
}
return category, nil
}
// DeleteCategory deletes a category
func (c *Client) DeleteCategory(projectIDOrKey interface{}, categoryID int) (*Category, error) {
return c.DeleteCategoryContext(context.Background(), projectIDOrKey, categoryID)
}
// DeleteCategoryContext deletes a category with Context
func (c *Client) DeleteCategoryContext(ctx context.Context, projectIDOrKey interface{}, categoryID int) (*Category, error) {
u := fmt.Sprintf("/api/v2/projects/%v/categories/%v", projectIDOrKey, categoryID)
req, err := c.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
category := new(Category)
if err := c.Do(ctx, req, &category); err != nil {
return nil, err
}
return category, nil
}
// CreateCategoryInput specifies parameters to the CreateCategory method.
type CreateCategoryInput struct {
Name *string `json:"name"`
}
// UpdateCategoryInput specifies parameters to the UpdateCategory method.
type UpdateCategoryInput struct {
Name *string `json:"name"`
}