forked from ctreminiom/go-atlassian
/
label_impl.go
63 lines (50 loc) · 1.59 KB
/
label_impl.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
package internal
import (
"context"
"fmt"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/jira"
"net/http"
"net/url"
"strconv"
)
func NewLabelService(client service.Connector, version string) (*LabelService, error) {
if version == "" {
return nil, model.ErrNoVersionProvided
}
return &LabelService{
internalClient: &internalLabelServiceImpl{c: client, version: version},
}, nil
}
type LabelService struct {
internalClient jira.LabelConnector
}
// Gets returns a paginated list of labels.
//
// GET /rest/api/{2-3}/label
//
// https://docs.go-atlassian.io/jira-software-cloud/issues/labels#get-all-labels
func (i *LabelService) Gets(ctx context.Context, startAt, maxResults int) (*model.IssueLabelsScheme, *model.ResponseScheme, error) {
return i.internalClient.Gets(ctx, startAt, maxResults)
}
type internalLabelServiceImpl struct {
c service.Connector
version string
}
func (i *internalLabelServiceImpl) Gets(ctx context.Context, startAt, maxResults int) (*model.IssueLabelsScheme, *model.ResponseScheme, error) {
params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))
endpoint := fmt.Sprintf("rest/api/%v/label?%v", i.version, params.Encode())
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
labels := new(model.IssueLabelsScheme)
response, err := i.c.Call(request, labels)
if err != nil {
return nil, response, err
}
return labels, response, nil
}