Skip to content

Commit f5f15d9

Browse files
Return team id when adding team
1 parent 4d890c7 commit f5f15d9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

team.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,31 @@ func (c *Client) Team(id int64) (*Team, error) {
7979
// AddTeam makes a new team
8080
// email arg is an optional value.
8181
// If you don't want to set email, please set "" (empty string).
82-
func (c *Client) AddTeam(name string, email string) error {
82+
// When team creation is successful, returns the team id
83+
func (c *Client) AddTeam(name string, email string) (int64, error) {
84+
id := int64(0)
8385
path := fmt.Sprintf("/api/teams")
86+
8487
team := Team{
8588
Name: name,
8689
Email: email,
8790
}
8891
data, err := json.Marshal(team)
8992
if err != nil {
90-
return err
93+
return id, err
9194
}
9295

93-
return c.request("POST", path, nil, bytes.NewBuffer(data), nil)
96+
tmp := struct {
97+
Id int64 `json:"teamId"`
98+
}{}
99+
100+
err = c.request("POST", path, nil, bytes.NewBuffer(data), &tmp)
101+
102+
if err != nil {
103+
return id, err
104+
}
105+
106+
return tmp.Id, err
94107
}
95108

96109
// UpdateTeam updates a Grafana team.

teams_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ func TestAddTeam(t *testing.T) {
158158
name := "TestTeam"
159159
email := ""
160160

161-
err := client.AddTeam(name, email)
161+
id, err := client.AddTeam(name, email)
162162
if err != nil {
163163
t.Error(err)
164164
}
165+
if id == 0 {
166+
t.Error("AddTeam returned an invalid id.")
167+
}
165168
}
166169

167170
func TestUpdateTeam(t *testing.T) {

0 commit comments

Comments
 (0)