Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit c87fc20

Browse files
authored
Merge pull request #6 from jonathan-dorsey/master
Return team ID when adding team
2 parents 2884a6a + 7bd9725 commit c87fc20

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: team.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,29 @@ 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 := "/api/teams"
8486
team := Team{
8587
Name: name,
8688
Email: email,
8789
}
8890
data, err := json.Marshal(team)
8991
if err != nil {
90-
return err
92+
return id, err
9193
}
9294

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

96107
// UpdateTeam updates a Grafana team.

Diff for: teams_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ func TestAddTeam(t *testing.T) {
159159
name := "TestTeam"
160160
email := ""
161161

162-
err := client.AddTeam(name, email)
162+
id, err := client.AddTeam(name, email)
163163
if err != nil {
164164
t.Error(err)
165165
}
166+
if id == 0 {
167+
t.Error("AddTeam returned an invalid ID")
168+
}
166169
}
167170

168171
func TestUpdateTeam(t *testing.T) {

0 commit comments

Comments
 (0)