summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-13 21:26:51 +0900
committerGeorge Goldberg <george@gberg.me>2017-03-13 12:26:51 +0000
commit8731465957ba41c1f828285e19ee3bb234e2ef58 (patch)
tree4051efe2fb0ec981e7004c32cf79d3592471fdfb /store
parent3559fb7959cf008b038239f2e7c43e604c44cd31 (diff)
downloadchat-8731465957ba41c1f828285e19ee3bb234e2ef58.tar.gz
chat-8731465957ba41c1f828285e19ee3bb234e2ef58.tar.bz2
chat-8731465957ba41c1f828285e19ee3bb234e2ef58.zip
Endpoint for APIv4: GET /team/{team_id}/channels (#5681)
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go34
-rw-r--r--store/sql_channel_store_test.go85
-rw-r--r--store/store.go1
3 files changed, 120 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 27a00f484..802a5a49d 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -550,6 +550,40 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in
return storeChannel
}
+func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ data := &model.ChannelList{}
+ _, err := s.GetReplica().Select(data,
+ `SELECT
+ *
+ FROM
+ Channels
+ WHERE
+ TeamId = :TeamId
+ AND Type = 'O'
+ AND DeleteAt = 0
+ ORDER BY DisplayName
+ LIMIT :Limit
+ OFFSET :Offset`,
+ map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset})
+
+ if err != nil {
+ result.Err = model.NewLocAppError("SqlChannelStore.GetPublicChannelsForTeam", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error())
+ } else {
+ result.Data = data
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
type channelIdWithCountAndUpdateAt struct {
Id string
TotalMsgCount int64
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 7b06dff8f..0e726eab7 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -775,6 +775,91 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
}
}
+func TestChannelStoreGetPublicChannelsForTeam(t *testing.T) {
+ Setup()
+
+ o1 := model.Channel{}
+ o1.TeamId = model.NewId()
+ o1.DisplayName = "OpenChannel1Team1"
+ o1.Name = "a" + model.NewId() + "b"
+ o1.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o1))
+
+ o2 := model.Channel{}
+ o2.TeamId = model.NewId()
+ o2.DisplayName = "OpenChannel1Team2"
+ o2.Name = "a" + model.NewId() + "b"
+ o2.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o2))
+
+ o3 := model.Channel{}
+ o3.TeamId = o1.TeamId
+ o3.DisplayName = "PrivateChannel1Team1"
+ o3.Name = "a" + model.NewId() + "b"
+ o3.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o3))
+
+ cresult := <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 0, 100)
+ if cresult.Err != nil {
+ t.Fatal(cresult.Err)
+ }
+ list := cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list")
+ }
+
+ if (*list)[0].Name != o1.Name {
+ t.Fatal("missing channel")
+ }
+
+ o4 := model.Channel{}
+ o4.TeamId = o1.TeamId
+ o4.DisplayName = "OpenChannel2Team1"
+ o4.Name = "a" + model.NewId() + "b"
+ o4.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o4))
+
+ cresult = <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 0, 100)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 2 {
+ t.Fatal("wrong list length")
+ }
+
+ cresult = <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 0, 1)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list length")
+ }
+
+ cresult = <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 1, 1)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list length")
+ }
+
+ if r1 := <-store.Channel().AnalyticsTypeCount(o1.TeamId, model.CHANNEL_OPEN); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.(int64) != 2 {
+ t.Log(r1.Data)
+ t.Fatal("wrong value")
+ }
+ }
+
+ if r1 := <-store.Channel().AnalyticsTypeCount(o1.TeamId, model.CHANNEL_PRIVATE); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.(int64) != 1 {
+ t.Log(r1.Data)
+ t.Fatal("wrong value")
+ }
+ }
+}
+
func TestChannelStoreGetChannelCounts(t *testing.T) {
Setup()
diff --git a/store/store.go b/store/store.go
index 330bc5716..8bc578114 100644
--- a/store/store.go
+++ b/store/store.go
@@ -101,6 +101,7 @@ type ChannelStore interface {
GetDeletedByName(team_id string, name string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
+ GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel