Этот коммит содержится в:
Shota Gvinepadze
2019-06-25 17:14:01 +04:00
коммит произвёл Jesús Espino
родитель d1b1b319cf
Коммит e9cb343ba7
5 изменённых файлов: 51 добавлений и 50 удалений

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

@@ -1798,11 +1798,7 @@ func (a *App) SearchAllChannels(term string, opts model.ChannelSearchOpts) (*mod
term = strings.TrimSpace(term)
result := <-a.Srv.Store.Channel().SearchAllChannels(term, storeOpts)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.ChannelListWithTeamData), nil
return a.Srv.Store.Channel().SearchAllChannels(term, storeOpts)
}
func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {

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

@@ -2098,8 +2098,7 @@ func (s SqlChannelStore) SearchInTeam(teamId string, term string, includeDeleted
})
}
func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearchOpts) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
query := s.getQueryBuilder().
Select("c.*, t.DisplayName AS TeamDisplayName, t.Name AS TeamName, t.UpdateAt as TeamUpdateAt").
From("Channels AS c").
@@ -2130,18 +2129,16 @@ func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearch
queryString, args, err := query.ToSql()
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.SearchAllChannels", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
return
return nil, model.NewAppError("SqlChannelStore.SearchAllChannels", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
}
var channels model.ChannelListWithTeamData
if _, err := s.GetReplica().Select(&channels, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Search", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
return nil, model.NewAppError("SqlChannelStore.Search", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
}
result.Data = &channels
})
return &channels, nil
}
func (s SqlChannelStore) SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError) {

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

@@ -183,7 +183,7 @@ type ChannelStore interface {
GetMembersForUserWithPagination(teamId, userId string, page, perPage int) StoreChannel
AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) StoreChannel
SearchAllChannels(term string, opts ChannelSearchOpts) StoreChannel
SearchAllChannels(term string, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError)
SearchInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError)
SearchGroupChannels(userId, term string) (*model.ChannelList, *model.AppError)

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

@@ -2547,9 +2547,8 @@ func testChannelStoreSearchAllChannels(t *testing.T, ss store.Store) {
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
result := <-ss.Channel().SearchAllChannels(testCase.Term, testCase.Opts)
require.Nil(t, result.Err)
channels := result.Data.(*model.ChannelListWithTeamData)
channels, err := ss.Channel().SearchAllChannels(testCase.Term, testCase.Opts)
require.Nil(t, err)
require.Equal(t, len(*testCase.ExpectedResults), len(*channels))
for i, expected := range *testCase.ExpectedResults {
require.Equal(t, (*channels)[i].Id, expected.Id)

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

@@ -1291,19 +1291,28 @@ func (_m *ChannelStore) SaveMember(member *model.ChannelMember) store.StoreChann
}
// SearchAllChannels provides a mock function with given fields: term, opts
func (_m *ChannelStore) SearchAllChannels(term string, opts store.ChannelSearchOpts) store.StoreChannel {
func (_m *ChannelStore) SearchAllChannels(term string, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
ret := _m.Called(term, opts)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string, store.ChannelSearchOpts) store.StoreChannel); ok {
var r0 *model.ChannelListWithTeamData
if rf, ok := ret.Get(0).(func(string, store.ChannelSearchOpts) *model.ChannelListWithTeamData); ok {
r0 = rf(term, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.ChannelListWithTeamData)
}
}
return r0
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, store.ChannelSearchOpts) *model.AppError); ok {
r1 = rf(term, opts)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// SearchGroupChannels provides a mock function with given fields: userId, term