mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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:
committed by
Eli Yukelzon
parent
3993cac4ed
commit
d1b1b319cf
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user