* APIv4 post /channels/ids

* updated enpoint as /teams/{team_id}/channels/ids
Этот коммит содержится в:
Saturnino Abril
2017-03-27 20:41:40 +09:00
коммит произвёл enahum
родитель 720ee81113
Коммит 01aaccb340
8 изменённых файлов: 259 добавлений и 5 удалений

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

@@ -619,6 +619,56 @@ func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, lim
return storeChannel
}
func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
props := make(map[string]interface{})
props["teamId"] = teamId
idQuery := ""
for index, channelId := range channelIds {
if len(idQuery) > 0 {
idQuery += ", "
}
props["channelId"+strconv.Itoa(index)] = channelId
idQuery += ":channelId" + strconv.Itoa(index)
}
data := &model.ChannelList{}
_, err := s.GetReplica().Select(data,
`SELECT
*
FROM
Channels
WHERE
TeamId = :teamId
AND Type = 'O'
AND DeleteAt = 0
AND Id IN (`+idQuery+`)
ORDER BY DisplayName`,
props)
if err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.get.app_error", nil, err.Error())
}
if len(*data) == 0 {
result.Err = model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.not_found.app_error", nil, "", http.StatusNotFound)
}
result.Data = data
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
type channelIdWithCountAndUpdateAt struct {
Id string
TotalMsgCount int64

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

@@ -934,6 +934,87 @@ func TestChannelStoreGetPublicChannelsForTeam(t *testing.T) {
}
}
func TestChannelStoreGetPublicChannelsByIdsForTeam(t *testing.T) {
Setup()
teamId1 := model.NewId()
oc1 := model.Channel{}
oc1.TeamId = teamId1
oc1.DisplayName = "OpenChannel1Team1"
oc1.Name = "a" + model.NewId() + "b"
oc1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&oc1))
oc2 := model.Channel{}
oc2.TeamId = model.NewId()
oc2.DisplayName = "OpenChannel2TeamOther"
oc2.Name = "a" + model.NewId() + "b"
oc2.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&oc2))
pc3 := model.Channel{}
pc3.TeamId = teamId1
pc3.DisplayName = "PrivateChannel3Team1"
pc3.Name = "a" + model.NewId() + "b"
pc3.Type = model.CHANNEL_PRIVATE
Must(store.Channel().Save(&pc3))
cids := []string{oc1.Id}
cresult := <-store.Channel().GetPublicChannelsByIdsForTeam(teamId1, cids)
list := cresult.Data.(*model.ChannelList)
if len(*list) != 1 {
t.Fatal("should return 1 channel")
}
if (*list)[0].Id != oc1.Id {
t.Fatal("missing channel")
}
cids = append(cids, oc2.Id)
cids = append(cids, model.NewId())
cids = append(cids, pc3.Id)
cresult = <-store.Channel().GetPublicChannelsByIdsForTeam(teamId1, cids)
list = cresult.Data.(*model.ChannelList)
if len(*list) != 1 {
t.Fatal("should return 1 channel")
}
oc4 := model.Channel{}
oc4.TeamId = teamId1
oc4.DisplayName = "OpenChannel4Team1"
oc4.Name = "a" + model.NewId() + "b"
oc4.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&oc4))
cids = append(cids, oc4.Id)
cresult = <-store.Channel().GetPublicChannelsByIdsForTeam(teamId1, cids)
list = cresult.Data.(*model.ChannelList)
if len(*list) != 2 {
t.Fatal("should return 2 channels")
}
if (*list)[0].Id != oc1.Id {
t.Fatal("missing channel")
}
if (*list)[1].Id != oc4.Id {
t.Fatal("missing channel")
}
cids = cids[:0]
cids = append(cids, model.NewId())
cresult = <-store.Channel().GetPublicChannelsByIdsForTeam(teamId1, cids)
list = cresult.Data.(*model.ChannelList)
if len(*list) != 0 {
t.Fatal("should not return a channel")
}
}
func TestChannelStoreGetChannelCounts(t *testing.T) {
Setup()

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

@@ -103,6 +103,7 @@ type ChannelStore interface {
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel