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

Return team id when adding team #6

Merged
merged 4 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions team.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,30 @@ func (c *Client) Team(id int64) (*Team, error) {
// AddTeam makes a new team
// email arg is an optional value.
// If you don't want to set email, please set "" (empty string).
func (c *Client) AddTeam(name string, email string) error {
// When team creation is successful, returns the team ID.
func (c *Client) AddTeam(name string, email string) (int64, error) {
id := int64(0)
path := fmt.Sprintf("/api/teams")

team := Team{
Name: name,
Email: email,
}
data, err := json.Marshal(team)
if err != nil {
return err
return id, err
}

return c.request("POST", path, nil, bytes.NewBuffer(data), nil)
tmp := struct {
ID int64 `json:"teamId"`
}{}

err = c.request("POST", path, nil, bytes.NewBuffer(data), &tmp)
if err != nil {
return id, err
}

return tmp.ID, err
}

// UpdateTeam updates a Grafana team.
Expand Down
5 changes: 4 additions & 1 deletion teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ func TestAddTeam(t *testing.T) {
name := "TestTeam"
email := ""

err := client.AddTeam(name, email)
id, err := client.AddTeam(name, email)
if err != nil {
t.Error(err)
}
if id == 0 {
t.Error("AddTeam returned an invalid ID")
}
}

func TestUpdateTeam(t *testing.T) {
Expand Down