-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.go
62 lines (51 loc) · 1.63 KB
/
team.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
package employmenthero
import (
"context"
"fmt"
"net/http"
)
type TeamListData struct {
Items []Team `json:"items"`
ListResponse
}
type TeamListDataResponse struct {
Data TeamListData `json:"data"`
}
// Get returns a list of [Team] resources
//
// Example:
//
// response, err := c.ListTeams(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", ListParams{})
// teams := response.Data.Items
func (c *Client) ListTeams(ctx context.Context, oid string, tp ListParams) (*TeamListDataResponse, error) {
req, err := c.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/api/v1/organisations/%s/teams", c.APIBase, oid), nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("page_index", tp.PageIndex)
q.Add("item_per_page", tp.ItemPerPage)
req.URL.RawQuery = q.Encode()
response := &TeamListDataResponse{}
err = c.SendWithAuth(req, response)
return response, err
}
// Get returns a list of [Employee] resources which belong to one [Team]
//
// Example:
//
// response, err := c.ListEmployeesByTeam(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXXX-YYYY-ZZZZ", ListParams{})
// employees := response.Data.Items
func (c *Client) ListEmployeesByTeam(ctx context.Context, oid string, tid string, tp ListParams) (*EmployeeListReponse, error) {
req, err := c.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/api/v1/organisations/%s/teams/%s/employees", c.APIBase, oid, tid), nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("page_index", tp.PageIndex)
q.Add("item_per_page", tp.ItemPerPage)
req.URL.RawQuery = q.Encode()
response := &EmployeeListReponse{}
err = c.SendWithAuth(req, response)
return response, err
}