Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Return team id when adding team #64

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
19 changes: 16 additions & 3 deletions team.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,31 @@ 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