Migrate GetDeleted method from ChannelStore to return error interface (#14710)

* Migrate GetDeleted method from ChannelStore to return error interface

* Moving i18n translations to the correct place

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Этот коммит содержится в:
Rodrigo Villablanca
2020-06-11 00:07:37 -04:00
коммит произвёл GitHub
родитель f2253df8a1
Коммит 9b0ae49b55
8 изменённых файлов: 40 добавлений и 31 удалений

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

@@ -1589,7 +1589,18 @@ func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.A
}
func (a *App) GetDeletedChannels(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
return a.Srv().Store.Channel().GetDeleted(teamId, offset, limit, userId)
list, err := a.Srv().Store.Channel().GetDeleted(teamId, offset, limit, userId)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.missing.app_error", nil, err.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.existing.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return list, nil
}
func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {

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

@@ -3006,6 +3006,14 @@
"id": "app.channel.get_all_channels_count.app_error",
"translation": "Unable to count all the channels."
},
{
"id": "app.channel.get_deleted.existing.app_error",
"translation": "Unable to find the existing deleted channel."
},
{
"id": "app.channel.get_deleted.missing.app_error",
"translation": "No deleted channels exist."
},
{
"id": "app.channel.move_channel.members_do_not_match.error",
"translation": "Unable to move a channel unless all its members are already members of the destination team."
@@ -6178,14 +6186,6 @@
"id": "store.sql_channel.get_channels_by_ids.not_found.app_error",
"translation": "No channel found."
},
{
"id": "store.sql_channel.get_deleted.existing.app_error",
"translation": "Unable to find the existing deleted channel."
},
{
"id": "store.sql_channel.get_deleted.missing.app_error",
"translation": "No deleted channels exist."
},
{
"id": "store.sql_channel.get_deleted_by_name.existing.app_error",
"translation": "Unable to find the existing deleted channel."

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

@@ -972,7 +972,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelsByScheme(schemeId string, offs
return resultVar0, resultVar1
}
func (s *OpenTracingLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetDeleted")
s.Root.Store.SetContext(newCtx)

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

@@ -1263,7 +1263,7 @@ func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Ch
return &channel, nil
}
func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId string) (*model.ChannelList, error) {
channels := &model.ChannelList{}
query := `
@@ -1282,9 +1282,9 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
if _, err := s.GetReplica().Select(channels, query, map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset, "UserId": userId}); err != nil {
if err == sql.ErrNoRows {
return nil, model.NewAppError("SqlChannelStore.GetDeleted", "store.sql_channel.get_deleted.missing.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusNotFound)
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s,UserId=%s", teamId, userId))
}
return nil, model.NewAppError("SqlChannelStore.GetDeleted", "store.sql_channel.get_deleted.existing.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to get deleted channels with TeamId=%s and UserId=%s", teamId, userId)
}
return channels, nil

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

@@ -147,7 +147,7 @@ type ChannelStore interface {
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError)
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError)
GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError)
GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error)
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
GetAllChannelsCount(opts ChannelSearchOpts) (int64, error)

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

@@ -756,8 +756,8 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) {
err := ss.Channel().Delete(o1.Id, model.GetMillis())
require.Nil(t, err, "channel should have been deleted")
list, err := ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
require.Nil(t, err, err)
list, nErr := ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
require.Nil(t, nErr, nErr)
require.Len(t, *list, 1, "wrong list")
require.Equal(t, o1.Name, (*list)[0].Name, "missing channel")
@@ -769,8 +769,8 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) {
_, nErr = ss.Channel().Save(&o2, -1)
require.Nil(t, nErr)
list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
require.Nil(t, err, err)
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
require.Nil(t, nErr, nErr)
require.Len(t, *list, 1, "wrong list")
o3 := model.Channel{}
@@ -785,16 +785,16 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) {
err = ss.Channel().Delete(o3.Id, model.GetMillis())
require.Nil(t, err, "channel should have been deleted")
list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
require.Nil(t, err, err)
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
require.Nil(t, nErr, nErr)
require.Len(t, *list, 2, "wrong list length")
list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 1, userId)
require.Nil(t, err, err)
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 1, userId)
require.Nil(t, nErr, nErr)
require.Len(t, *list, 1, "wrong list length")
list, err = ss.Channel().GetDeleted(o1.TeamId, 1, 1, userId)
require.Nil(t, err, err)
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 1, 1, userId)
require.Nil(t, nErr, nErr)
require.Len(t, *list, 1, "wrong list length")
}

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

@@ -660,7 +660,7 @@ func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit i
}
// GetDeleted provides a mock function with given fields: team_id, offset, limit, userId
func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) {
ret := _m.Called(team_id, offset, limit, userId)
var r0 *model.ChannelList
@@ -672,13 +672,11 @@ func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int, string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, int, int, string) error); ok {
r1 = rf(team_id, offset, limit, userId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1

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

@@ -904,7 +904,7 @@ func (s *TimerLayerChannelStore) GetChannelsByScheme(schemeId string, offset int
return resultVar0, resultVar1
}
func (s *TimerLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
func (s *TimerLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) {
start := timemodule.Now()
resultVar0, resultVar1 := s.ChannelStore.GetDeleted(team_id, offset, limit, userId)