-
Notifications
You must be signed in to change notification settings - Fork 0
/
crew_custom_field_template_group.go
92 lines (82 loc) · 2.9 KB
/
crew_custom_field_template_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
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
package smarthr
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
)
type CrewCustomFieldTemplateGroup struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Position int `json:"position,omitempty"`
AccessType string `json:"access_type,omitempty" validate:"omitempty,eq=read_and_update|eq=hidden|eq=read_and_update_values"`
Templates *CrewCustomFieldTemplate `json:"templates,omitempty"`
UpdatedAt string `json:"updated_at"`
CreatedAt string `json:"created_at"`
}
func (c *Client) DeleteCrewCustomFieldTemplateGroup(ctx context.Context, id string) error {
p := fmt.Sprintf("/v1/crew_custom_field_template_groups/%s", id)
_, err := c.delete(ctx, p)
return errors.WithStack(err)
}
func (c *Client) GetCrewCustomFieldTemplateGroup(ctx context.Context, id string) (*CrewCustomFieldTemplateGroup, error) {
p := fmt.Sprintf("/v1/crew_custom_field_template_groups/%s", id)
res, err := c.get(ctx, p, nil)
if err != nil {
return nil, errors.WithStack(err)
}
var group CrewCustomFieldTemplateGroup
if err := decodeBody(res, &group); err != nil {
return nil, errors.WithStack(err)
}
return &group, nil
}
func (c *Client) UpdateCrewCustomFieldTemplateGroup(ctx context.Context, id string, data map[string]interface{}) error {
b, err := json.Marshal(data)
if err != nil {
return errors.WithStack(err)
}
_, err = c.patch(ctx, fmt.Sprintf("/v1/crew_custom_field_template_groups/%s", id), bytes.NewBuffer(b))
return errors.WithStack(err)
}
type ListCrewCustomFieldTemplateGroupsOptions struct {
Page uint `url:"page,omitempty"`
PerPage uint `url:"per_page,omitempty"`
Embed string `url:"embed,omitempty" validate:"omitempty,eq=templates"`
}
func (opt *ListCrewCustomFieldTemplateGroupsOptions) Validate() error {
if opt == nil {
return nil
}
err := validator.Struct(opt)
return errors.WithStack(err)
}
func (c *Client) ListCrewCustomFieldTemplateGroups(ctx context.Context, opt *ListCrewCustomFieldTemplateGroupsOptions) ([]CrewCustomFieldTemplateGroup, error) {
if err := opt.Validate(); err != nil {
return nil, errors.WithStack(err)
}
res, err := c.get(ctx, "/v1/crew_custom_field_template_groups", opt)
if err != nil {
return nil, errors.WithStack(err)
}
var groups []CrewCustomFieldTemplateGroup
if err := decodeBody(res, &groups); err != nil {
return nil, errors.WithStack(err)
}
return groups, nil
}
func (c *Client) CreateCrewCustomFieldTemplateGroup(ctx context.Context, group *CrewCustomFieldTemplateGroup) error {
if group == nil {
return nil
}
if err := validator.Struct(group); err != nil {
return errors.WithStack(err)
}
b, err := json.Marshal(group)
if err != nil {
return errors.WithStack(err)
}
_, err = c.post(ctx, "/v1/crew_custom_field_template_groups", bytes.NewBuffer(b))
return errors.WithStack(err)
}