-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrole.go
More file actions
47 lines (40 loc) · 1 KB
/
role.go
File metadata and controls
47 lines (40 loc) · 1 KB
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
package forecast
import (
"errors"
"fmt"
)
type rolesContainer struct {
Roles Roles `json:"roles"`
}
type roleContainer struct {
Role Role `json:"role"`
}
// Roles is a list of roles
type Roles []Role
// Role is a role that can be assigned to a person in Forecast
type Role struct {
ID int `json:"id"`
Name string `json:"name"`
PlaceholderIDs []int `json:"placeholder_ids"`
PersonIDs []int `json:"person_ids"`
HarvestRoleID int `json:"harvest_role_id"`
}
// Roles returns all roles in Forecast
func (api *API) Roles() (Roles, error) {
container, err := get[rolesContainer](api, "roles")
if err != nil {
return nil, err
}
return container.Roles, nil
}
// Role returns the role with the requested ID
func (api *API) Role(id int) (*Role, error) {
if id == 0 {
return nil, errors.New("cannot retrieve a rolee with an id of 0")
}
container, err := get[roleContainer](api, fmt.Sprintf("roles/%v", id))
if err != nil {
return nil, err
}
return &container.Role, nil
}