Removing channel list alias from apiv4 client (#6383)

Этот коммит содержится в:
Christopher Speller
2017-05-10 11:41:56 -04:00
коммит произвёл Corey Hulen
родитель a678981861
Коммит 4f589e077c
3 изменённых файлов: 40 добавлений и 29 удалений

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

@@ -502,7 +502,7 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "") channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 0 { if len(channels) != 0 {
t.Fatal("should be no deleted channels") t.Fatal("should be no deleted channels")
} }
@@ -512,7 +512,7 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "") channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 1 { if len(channels) != 1 {
t.Fatal("should be 1 deleted channel") t.Fatal("should be 1 deleted channel")
} }
@@ -521,19 +521,19 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "") channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 2 { if len(channels) != 2 {
t.Fatal("should be 2 deleted channels") t.Fatal("should be 2 deleted channels")
} }
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 1, "") channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 1, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 1 { if len(channels) != 1 {
t.Fatal("should be one channel per page") t.Fatal("should be one channel per page")
} }
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 1, 1, "") channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 1, 1, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 1 { if len(channels) != 1 {
t.Fatal("should be one channel per page") t.Fatal("should be one channel per page")
} }
} }
@@ -548,11 +548,11 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
channels, resp := Client.GetPublicChannelsForTeam(team.Id, 0, 100, "") channels, resp := Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 4 { if len(channels) != 4 {
t.Fatal("wrong length") t.Fatal("wrong length")
} }
for i, c := range *channels { for i, c := range channels {
if c.Type != model.CHANNEL_OPEN { if c.Type != model.CHANNEL_OPEN {
t.Fatal("should include open channel only") t.Fatal("should include open channel only")
} }
@@ -567,11 +567,11 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
privateChannel := th.CreatePrivateChannel() privateChannel := th.CreatePrivateChannel()
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "") channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 4 { if len(channels) != 4 {
t.Fatal("wrong length") t.Fatal("wrong length")
} }
for _, c := range *channels { for _, c := range channels {
if c.Type != model.CHANNEL_OPEN { if c.Type != model.CHANNEL_OPEN {
t.Fatal("should not include private channel") t.Fatal("should not include private channel")
} }
@@ -583,19 +583,19 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 1, "") channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 1, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 1 { if len(channels) != 1 {
t.Fatal("should be one channel per page") t.Fatal("should be one channel per page")
} }
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 1, 1, "") channels, resp = Client.GetPublicChannelsForTeam(team.Id, 1, 1, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 1 { if len(channels) != 1 {
t.Fatal("should be one channel per page") t.Fatal("should be one channel per page")
} }
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 10000, 100, "") channels, resp = Client.GetPublicChannelsForTeam(team.Id, 10000, 100, "")
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 0 { if len(channels) != 0 {
t.Fatal("should be no channel") t.Fatal("should be no channel")
} }
@@ -629,11 +629,11 @@ func TestGetPublicChannelsByIdsForTeam(t *testing.T) {
channels, resp := Client.GetPublicChannelsByIdsForTeam(teamId, input) channels, resp := Client.GetPublicChannelsByIdsForTeam(teamId, input)
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 1 { if len(channels) != 1 {
t.Fatal("should return 1 channel") t.Fatal("should return 1 channel")
} }
if (*channels)[0].DisplayName != output[0] { if (channels)[0].DisplayName != output[0] {
t.Fatal("missing channel") t.Fatal("missing channel")
} }
@@ -646,11 +646,11 @@ func TestGetPublicChannelsByIdsForTeam(t *testing.T) {
channels, resp = Client.GetPublicChannelsByIdsForTeam(teamId, input) channels, resp = Client.GetPublicChannelsByIdsForTeam(teamId, input)
CheckNoError(t, resp) CheckNoError(t, resp)
if len(*channels) != 2 { if len(channels) != 2 {
t.Fatal("should return 2 channels") t.Fatal("should return 2 channels")
} }
for i, c := range *channels { for i, c := range channels {
if c.DisplayName != output[i] { if c.DisplayName != output[i] {
t.Fatal("missing channel") t.Fatal("missing channel")
} }
@@ -689,7 +689,7 @@ func TestGetChannelsForTeamForUser(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
found := make([]bool, 3) found := make([]bool, 3)
for _, c := range *channels { for _, c := range channels {
if c.Id == th.BasicChannel.Id { if c.Id == th.BasicChannel.Id {
found[0] = true found[0] = true
} else if c.Id == th.BasicChannel2.Id { } else if c.Id == th.BasicChannel2.Id {
@@ -739,7 +739,7 @@ func TestSearchChannels(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
found := false found := false
for _, c := range *channels { for _, c := range channels {
if c.Type != model.CHANNEL_OPEN { if c.Type != model.CHANNEL_OPEN {
t.Fatal("should only return public channels") t.Fatal("should only return public channels")
} }
@@ -758,7 +758,7 @@ func TestSearchChannels(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
found = false found = false
for _, c := range *channels { for _, c := range channels {
if c.Id == th.BasicPrivateChannel.Id { if c.Id == th.BasicPrivateChannel.Id {
found = true found = true
} }

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

@@ -50,3 +50,14 @@ func ChannelListFromJson(data io.Reader) *ChannelList {
return nil return nil
} }
} }
func ChannelSliceFromJson(data io.Reader) []*Channel {
decoder := json.NewDecoder(data)
var o []*Channel
err := decoder.Decode(&o)
if err == nil {
return o
} else {
return nil
}
}

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

@@ -1270,54 +1270,54 @@ func (c *Client4) GetPinnedPosts(channelId string, etag string) (*PostList, *Res
} }
// GetPublicChannelsForTeam returns a list of public channels based on the provided team id string. // GetPublicChannelsForTeam returns a list of public channels based on the provided team id string.
func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) (*ChannelList, *Response) { func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) ([]*Channel, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage) query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag); err != nil { if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err} return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else { } else {
defer closeBody(r) defer closeBody(r)
return ChannelListFromJson(r.Body), BuildResponse(r) return ChannelSliceFromJson(r.Body), BuildResponse(r)
} }
} }
// GetDeletedChannelsForTeam returns a list of public channels based on the provided team id string. // GetDeletedChannelsForTeam returns a list of public channels based on the provided team id string.
func (c *Client4) GetDeletedChannelsForTeam(teamId string, page int, perPage int, etag string) (*ChannelList, *Response) { func (c *Client4) GetDeletedChannelsForTeam(teamId string, page int, perPage int, etag string) ([]*Channel, *Response) {
query := fmt.Sprintf("/deleted?page=%v&per_page=%v", page, perPage) query := fmt.Sprintf("/deleted?page=%v&per_page=%v", page, perPage)
if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag); err != nil { if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err} return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else { } else {
defer closeBody(r) defer closeBody(r)
return ChannelListFromJson(r.Body), BuildResponse(r) return ChannelSliceFromJson(r.Body), BuildResponse(r)
} }
} }
// GetPublicChannelsByIdsForTeam returns a list of public channels based on provided team id string // GetPublicChannelsByIdsForTeam returns a list of public channels based on provided team id string
func (c *Client4) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*ChannelList, *Response) { func (c *Client4) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) ([]*Channel, *Response) {
if r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/ids", ArrayToJson(channelIds)); err != nil { if r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/ids", ArrayToJson(channelIds)); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err} return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else { } else {
defer closeBody(r) defer closeBody(r)
return ChannelListFromJson(r.Body), BuildResponse(r) return ChannelSliceFromJson(r.Body), BuildResponse(r)
} }
} }
// GetChannelsForTeamForUser returns a list channels of on a team for a user. // GetChannelsForTeamForUser returns a list channels of on a team for a user.
func (c *Client4) GetChannelsForTeamForUser(teamId, userId, etag string) (*ChannelList, *Response) { func (c *Client4) GetChannelsForTeamForUser(teamId, userId, etag string) ([]*Channel, *Response) {
if r, err := c.DoApiGet(c.GetUserRoute(userId)+c.GetTeamRoute(teamId)+"/channels", etag); err != nil { if r, err := c.DoApiGet(c.GetUserRoute(userId)+c.GetTeamRoute(teamId)+"/channels", etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err} return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else { } else {
defer closeBody(r) defer closeBody(r)
return ChannelListFromJson(r.Body), BuildResponse(r) return ChannelSliceFromJson(r.Body), BuildResponse(r)
} }
} }
// SearchChannels returns the channels on a team matching the provided search term. // SearchChannels returns the channels on a team matching the provided search term.
func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) (*ChannelList, *Response) { func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) ([]*Channel, *Response) {
if r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/search", search.ToJson()); err != nil { if r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/search", search.ToJson()); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err} return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else { } else {
defer closeBody(r) defer closeBody(r)
return ChannelListFromJson(r.Body), BuildResponse(r) return ChannelSliceFromJson(r.Body), BuildResponse(r)
} }
} }