MM-16500: Adds ability to retrieve the total count of teams via the API. (#11325)

Этот коммит содержится в:
Martin Kraft
2019-06-24 17:05:34 -04:00
коммит произвёл Miguel de la Cruz
родитель 49d5037a89
Коммит c07b7046ca
6 изменённых файлов: 78 добавлений и 3 удалений

Просмотреть файл

@@ -1500,6 +1500,18 @@ func (c *Client4) GetAllTeams(etag string, page int, perPage int) ([]*Team, *Res
return TeamListFromJson(r.Body), BuildResponse(r)
}
// GetAllTeamsWithTotalCount returns all teams based on permissions.
func (c *Client4) GetAllTeamsWithTotalCount(etag string, page int, perPage int) ([]*Team, int64, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v&include_total_count=true", page, perPage)
r, err := c.DoApiGet(c.GetTeamsRoute()+query, etag)
if err != nil {
return nil, 0, BuildErrorResponse(r, err)
}
defer closeBody(r)
teamsListWithCount := TeamsWithCountFromJson(r.Body)
return teamsListWithCount.Teams, teamsListWithCount.TotalCount, BuildResponse(r)
}
// GetTeamByName returns a team based on the provided team name string.
func (c *Client4) GetTeamByName(name, etag string) (*Team, *Response) {
r, err := c.DoApiGet(c.GetTeamByNameRoute(name), etag)

Просмотреть файл

@@ -62,6 +62,11 @@ type Invites struct {
Invites []map[string]string `json:"invites"`
}
type TeamsWithCount struct {
Teams []*Team `json:"teams"`
TotalCount int64 `json:"total_count"`
}
func InvitesFromJson(data io.Reader) *Invites {
var o *Invites
json.NewDecoder(data).Decode(&o)
@@ -108,6 +113,17 @@ func TeamListToJson(t []*Team) string {
return string(b)
}
func TeamsWithCountToJson(tlc *TeamsWithCount) []byte {
b, _ := json.Marshal(tlc)
return b
}
func TeamsWithCountFromJson(data io.Reader) *TeamsWithCount {
var twc *TeamsWithCount
json.NewDecoder(data).Decode(&twc)
return twc
}
func TeamListFromJson(data io.Reader) []*Team {
var teams []*Team
json.NewDecoder(data).Decode(&teams)