[MM-16167] Migrate "Team.GetAllPrivateTeamPageListing" to Sync by def… (#11181)

* [MM-16167] Migrate "Team.GetAllPrivateTeamPageListing" to Sync by default

* Fix shadow variable error
Этот коммит содержится в:
piperRyan
2019-06-14 04:26:55 -06:00
коммит произвёл Jesús Espino
родитель 570e6f1a74
Коммит 1f02b0ce72
5 изменённых файлов: 32 добавлений и 36 удалений

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

@@ -631,11 +631,7 @@ func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) {
} }
func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) { func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {
result := <-a.Srv.Store.Team().GetAllPrivateTeamPageListing(offset, limit) return a.Srv.Store.Team().GetAllPrivateTeamPageListing(offset, limit)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Team), nil
} }
func (a *App) GetAllPublicTeams() ([]*model.Team, *model.AppError) { func (a *App) GetAllPublicTeams() ([]*model.Team, *model.AppError) {

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

@@ -400,22 +400,19 @@ func (s SqlTeamStore) GetAllPrivateTeamListing() store.StoreChannel {
}) })
} }
func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) store.StoreChannel { func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
return store.Do(func(result *store.StoreResult) { query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName LIMIT :Limit OFFSET :Offset" query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
} }
var data []*model.Team var data []*model.Team
if _, err := s.GetReplica().Select(&data, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil { if _, err := s.GetReplica().Select(&data, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
result.Err = model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
return }
}
result.Data = data return data, nil
})
} }
func (s SqlTeamStore) GetAllTeamListing() store.StoreChannel { func (s SqlTeamStore) GetAllTeamListing() store.StoreChannel {

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

@@ -93,7 +93,7 @@ type TeamStore interface {
GetAll() ([]*model.Team, *model.AppError) GetAll() ([]*model.Team, *model.AppError)
GetAllPage(offset int, limit int) StoreChannel GetAllPage(offset int, limit int) StoreChannel
GetAllPrivateTeamListing() StoreChannel GetAllPrivateTeamListing() StoreChannel
GetAllPrivateTeamPageListing(offset int, limit int) StoreChannel GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
GetAllTeamListing() StoreChannel GetAllTeamListing() StoreChannel
GetAllTeamPageListing(offset int, limit int) StoreChannel GetAllTeamPageListing(offset int, limit int) StoreChannel
GetTeamsByUserId(userId string) StoreChannel GetTeamsByUserId(userId string) StoreChannel

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

@@ -181,19 +181,28 @@ func (_m *TeamStore) GetAllPrivateTeamListing() store.StoreChannel {
} }
// GetAllPrivateTeamPageListing provides a mock function with given fields: offset, limit // GetAllPrivateTeamPageListing provides a mock function with given fields: offset, limit
func (_m *TeamStore) GetAllPrivateTeamPageListing(offset int, limit int) store.StoreChannel { func (_m *TeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
ret := _m.Called(offset, limit) ret := _m.Called(offset, limit)
var r0 store.StoreChannel var r0 []*model.Team
if rf, ok := ret.Get(0).(func(int, int) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
r0 = rf(offset, limit) r0 = rf(offset, limit)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).([]*model.Team)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(int, int) *model.AppError); ok {
r1 = rf(offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetAllTeamListing provides a mock function with given fields: // GetAllTeamListing provides a mock function with given fields:

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

@@ -683,11 +683,9 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(&o4) _, err = ss.Team().Save(&o4)
require.Nil(t, err) require.Nil(t, err)
if r1 := <-ss.Team().GetAllPrivateTeamPageListing(0, 10); r1.Err != nil { if teams, listErr := ss.Team().GetAllPrivateTeamPageListing(0, 10); listErr != nil {
t.Fatal(r1.Err) t.Fatal(listErr)
} else { } else {
teams := r1.Data.([]*model.Team)
for _, team := range teams { for _, team := range teams {
if team.AllowOpenInvite { if team.AllowOpenInvite {
t.Fatal("should have returned team with AllowOpenInvite as false") t.Fatal("should have returned team with AllowOpenInvite as false")
@@ -708,11 +706,9 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(&o5) _, err = ss.Team().Save(&o5)
require.Nil(t, err) require.Nil(t, err)
if r1 := <-ss.Team().GetAllPrivateTeamPageListing(0, 4); r1.Err != nil { if teams, listErr := ss.Team().GetAllPrivateTeamPageListing(0, 4); listErr != nil {
t.Fatal(r1.Err) t.Fatal(listErr)
} else { } else {
teams := r1.Data.([]*model.Team)
for _, team := range teams { for _, team := range teams {
if team.AllowOpenInvite { if team.AllowOpenInvite {
t.Fatal("should have returned team with AllowOpenInvite as false") t.Fatal("should have returned team with AllowOpenInvite as false")
@@ -724,11 +720,9 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
} }
} }
if r1 := <-ss.Team().GetAllPrivateTeamPageListing(1, 1); r1.Err != nil { if teams, listErr := ss.Team().GetAllPrivateTeamPageListing(1, 1); listErr != nil {
t.Fatal(r1.Err) t.Fatal(listErr)
} else { } else {
teams := r1.Data.([]*model.Team)
for _, team := range teams { for _, team := range teams {
if team.AllowOpenInvite { if team.AllowOpenInvite {
t.Fatal("should have returned team with AllowOpenInvite as false") t.Fatal("should have returned team with AllowOpenInvite as false")