MM-16499: Adds ability to retrieve channels with total count f… (#11375)

* MM-16499: Adds ability to retrieve channels with total count for pagination.

* MM-16499: Switches to custom package name for squirrel.
This commit is contained in:
Martin Kraft
2019-06-25 08:18:48 -04:00
committed by Eli Yukelzon
parent 3993cac4ed
commit d1b1b319cf
10 changed files with 175 additions and 25 deletions

View File

@@ -60,6 +60,11 @@ type ChannelWithTeamData struct {
TeamUpdateAt int64 `json:"team_update_at"`
}
type ChannelsWithCount struct {
Channels *ChannelListWithTeamData `json:"channels"`
TotalCount int64 `json:"total_count"`
}
type ChannelPatch struct {
DisplayName *string `json:"display_name"`
Name *string `json:"name"`
@@ -111,6 +116,17 @@ func (o *ChannelPatch) ToJson() string {
return string(b)
}
func (o *ChannelsWithCount) ToJson() []byte {
b, _ := json.Marshal(o)
return b
}
func ChannelsWithCountFromJson(data io.Reader) *ChannelsWithCount {
var o *ChannelsWithCount
json.NewDecoder(data).Decode(&o)
return o
}
func ChannelFromJson(data io.Reader) *Channel {
var o *Channel
json.NewDecoder(data).Decode(&o)

View File

@@ -1908,6 +1908,18 @@ func (c *Client4) GetAllChannels(page int, perPage int, etag string) (*ChannelLi
return ChannelListWithTeamDataFromJson(r.Body), BuildResponse(r)
}
// GetAllChannelsWithCount get all the channels including the total count. Must be a system administrator.
func (c *Client4) GetAllChannelsWithCount(page int, perPage int, etag string) (*ChannelListWithTeamData, int64, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v&include_total_count=true", page, perPage)
r, err := c.DoApiGet(c.GetChannelsRoute()+query, etag)
if err != nil {
return nil, 0, BuildErrorResponse(r, err)
}
defer closeBody(r)
cwc := ChannelsWithCountFromJson(r.Body)
return cwc.Channels, cwc.TotalCount, BuildResponse(r)
}
// CreateChannel creates a channel based on the provided channel struct.
func (c *Client4) CreateChannel(channel *Channel) (*Channel, *Response) {
r, err := c.DoApiPost(c.GetChannelsRoute(), channel.ToJson())