MM-15289 Migrate command.GetByTeam to sync by default (#10740)

Этот коммит содержится в:
Puneeth Reddy
2019-04-29 01:20:52 -07:00
коммит произвёл Jesús Espino
родитель 214e9d2ae0
Коммит 171058eb3d
6 изменённых файлов: 43 добавлений и 46 удалений

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

@@ -76,16 +76,14 @@ func (s SqlCommandStore) Get(id string) store.StoreChannel {
})
}
func (s SqlCommandStore) GetByTeam(teamId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var commands []*model.Command
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
var commands []*model.Command
if _, err := s.GetReplica().Select(&commands, "SELECT * FROM Commands WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
result.Err = model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
}
if _, err := s.GetReplica().Select(&commands, "SELECT * FROM Commands WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
return nil, model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
}
result.Data = commands
})
return commands, nil
}
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) store.StoreChannel {

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

@@ -406,7 +406,7 @@ type WebhookStore interface {
type CommandStore interface {
Save(webhook *model.Command) StoreChannel
Get(id string) StoreChannel
GetByTeam(teamId string) StoreChannel
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
GetByTrigger(teamId string, trigger string) StoreChannel
Delete(commandId string, time int64) StoreChannel
PermanentDeleteByTeam(teamId string) StoreChannel

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

@@ -72,18 +72,18 @@ func testCommandStoreGetByTeam(t *testing.T, ss store.Store) {
o1 = (<-ss.Command().Save(o1)).Data.(*model.Command)
if r1 := <-ss.Command().GetByTeam(o1.TeamId); r1.Err != nil {
t.Fatal(r1.Err)
if r1, err := ss.Command().GetByTeam(o1.TeamId); err != nil {
t.Fatal(err)
} else {
if r1.Data.([]*model.Command)[0].CreateAt != o1.CreateAt {
if r1[0].CreateAt != o1.CreateAt {
t.Fatal("invalid returned command")
}
}
if result := <-ss.Command().GetByTeam("123"); result.Err != nil {
t.Fatal(result.Err)
if result, err := ss.Command().GetByTeam("123"); err != nil {
t.Fatal(err)
} else {
if len(result.Data.([]*model.Command)) != 0 {
if len(result) != 0 {
t.Fatal("no commands should have returned")
}
}

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

@@ -62,19 +62,28 @@ func (_m *CommandStore) Get(id string) store.StoreChannel {
}
// GetByTeam provides a mock function with given fields: teamId
func (_m *CommandStore) GetByTeam(teamId string) store.StoreChannel {
func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
ret := _m.Called(teamId)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
var r0 []*model.Command
if rf, ok := ret.Get(0).(func(string) []*model.Command); ok {
r0 = rf(teamId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).([]*model.Command)
}
}
return r0
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
r1 = rf(teamId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetByTrigger provides a mock function with given fields: teamId, trigger