diff --git a/app/command.go b/app/command.go index a54739fd92..31d7400421 100644 --- a/app/command.go +++ b/app/command.go @@ -525,9 +525,6 @@ func (a *App) DeleteCommand(commandId string) *model.AppError { if !*a.Config().ServiceSettings.EnableCommands { return model.NewAppError("DeleteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented) } - result := <-a.Srv.Store.Command().Delete(commandId, model.GetMillis()) - if result.Err != nil { - return result.Err - } - return nil + + return a.Srv.Store.Command().Delete(commandId, model.GetMillis()) } diff --git a/store/sqlstore/command_store.go b/store/sqlstore/command_store.go index e15f6f1da2..32ae8acd34 100644 --- a/store/sqlstore/command_store.go +++ b/store/sqlstore/command_store.go @@ -102,13 +102,13 @@ func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) store.Store }) } -func (s SqlCommandStore) Delete(commandId string, time int64) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("Update Commands SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": commandId}) - if err != nil { - result.Err = model.NewAppError("SqlCommandStore.Delete", "store.sql_command.save.delete.app_error", nil, "id="+commandId+", err="+err.Error(), http.StatusInternalServerError) - } - }) +func (s SqlCommandStore) Delete(commandId string, time int64) *model.AppError { + _, err := s.GetMaster().Exec("Update Commands SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": commandId}) + if err != nil { + return model.NewAppError("SqlCommandStore.Delete", "store.sql_command.save.delete.app_error", nil, "id="+commandId+", err="+err.Error(), http.StatusInternalServerError) + } + + return nil } func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError { diff --git a/store/store.go b/store/store.go index cc537a010a..fc3002872b 100644 --- a/store/store.go +++ b/store/store.go @@ -414,7 +414,7 @@ type CommandStore interface { Get(id string) StoreChannel GetByTeam(teamId string) ([]*model.Command, *model.AppError) GetByTrigger(teamId string, trigger string) StoreChannel - Delete(commandId string, time int64) StoreChannel + Delete(commandId string, time int64) *model.AppError PermanentDeleteByTeam(teamId string) *model.AppError PermanentDeleteByUser(userId string) *model.AppError Update(hook *model.Command) (*model.Command, *model.AppError) diff --git a/store/storetest/command_store.go b/store/storetest/command_store.go index 3873c2b604..e3b2840ede 100644 --- a/store/storetest/command_store.go +++ b/store/storetest/command_store.go @@ -127,7 +127,10 @@ func testCommandStoreGetByTrigger(t *testing.T, ss store.Store) { } } - store.Must(ss.Command().Delete(o1.Id, model.GetMillis())) + err = ss.Command().Delete(o1.Id, model.GetMillis()) + if err != nil { + t.Fatal(err) + } if result := <-ss.Command().GetByTrigger(o1.TeamId, o1.Trigger); result.Err == nil { t.Fatal("no commands should have returned") @@ -155,8 +158,8 @@ func testCommandStoreDelete(t *testing.T, ss store.Store) { } } - if r2 := <-ss.Command().Delete(o1.Id, model.GetMillis()); r2.Err != nil { - t.Fatal(r2.Err) + if err := ss.Command().Delete(o1.Id, model.GetMillis()); err != nil { + t.Fatal(err) } if r3 := (<-ss.Command().Get(o1.Id)); r3.Err == nil { diff --git a/store/storetest/mocks/CommandStore.go b/store/storetest/mocks/CommandStore.go index e2ba2f6d2c..5ea4109ac6 100644 --- a/store/storetest/mocks/CommandStore.go +++ b/store/storetest/mocks/CommandStore.go @@ -37,15 +37,15 @@ func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppE } // Delete provides a mock function with given fields: commandId, time -func (_m *CommandStore) Delete(commandId string, time int64) store.StoreChannel { +func (_m *CommandStore) Delete(commandId string, time int64) *model.AppError { ret := _m.Called(commandId, time) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok { + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok { r0 = rf(commandId, time) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).(*model.AppError) } }