Adds the endpoints and store logic to get groups by team and by channel (#10502)

* Adds the endpoints and store logic to get groups by team and by channel

* Remove TODO comments

* Fix unit tests
Этот коммит содержится в:
Miguel de la Cruz
2019-04-02 21:02:51 +01:00
коммит произвёл GitHub
родитель 25fd962016
Коммит 2ce48aa6d1
15 изменённых файлов: 777 добавлений и 38 удалений

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

@@ -164,3 +164,19 @@ func (a *App) ChannelMembersToRemove() ([]*model.ChannelMember, *model.AppError)
}
return result.Data.([]*model.ChannelMember), nil
}
func (a *App) GetGroupsByChannel(channelId string, page, perPage int) ([]*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().GetGroupsByChannel(channelId, page, perPage)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Group), nil
}
func (a *App) GetGroupsByTeam(teamId string, page, perPage int) ([]*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().GetGroupsByTeam(teamId, page, perPage)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Group), nil
}

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

@@ -197,3 +197,55 @@ func TestDeleteGroupSyncable(t *testing.T) {
require.NotNil(t, err)
require.Nil(t, gs)
}
func TestGetGroupsByChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
// Create a group channel
groupSyncable := &model.GroupSyncable{
GroupId: group.Id,
AutoAdd: false,
SyncableId: th.BasicChannel.Id,
Type: model.GroupSyncableTypeChannel,
}
gs, err := th.App.CreateGroupSyncable(groupSyncable)
require.Nil(t, err)
require.NotNil(t, gs)
groups, err := th.App.GetGroupsByChannel(th.BasicChannel.Id, 0, 60)
require.Nil(t, err)
require.ElementsMatch(t, []*model.Group{group}, groups)
groups, err = th.App.GetGroupsByChannel(model.NewId(), 0, 60)
require.Nil(t, err)
require.Empty(t, groups)
}
func TestGetGroupsByTeam(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
// Create a group team
groupSyncable := &model.GroupSyncable{
GroupId: group.Id,
AutoAdd: false,
SyncableId: th.BasicTeam.Id,
Type: model.GroupSyncableTypeTeam,
}
gs, err := th.App.CreateGroupSyncable(groupSyncable)
require.Nil(t, err)
require.NotNil(t, gs)
groups, err := th.App.GetGroupsByTeam(th.BasicTeam.Id, 0, 60)
require.Nil(t, err)
require.ElementsMatch(t, []*model.Group{group}, groups)
groups, err = th.App.GetGroupsByTeam(model.NewId(), 0, 60)
require.Nil(t, err)
require.Empty(t, groups)
}