mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-18357: Adds pagination to team search. (#12910)
* MM-18357: Adds pagination to team search. * MM-18357: Adds new client method for paginated requests. * MM-18357: Adds feedback about non-supported pagination-permissions combo. * MM-18357: Removes unnecessary conversion. * MM-18357: Removes paginate parameter and uses nil on page and perpage instead.
This commit is contained in:
@@ -305,6 +305,26 @@ func (s SqlTeamStore) SearchAll(term string) ([]*model.Team, *model.AppError) {
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
// SearchAllPaged returns a teams list and the total count of teams that matched the search.
|
||||
func (s SqlTeamStore) SearchAllPaged(term string, page int, perPage int) ([]*model.Team, int64, *model.AppError) {
|
||||
var teams []*model.Team
|
||||
var totalCount int64
|
||||
offset := page * perPage
|
||||
|
||||
term = sanitizeSearchTerm(term, "\\")
|
||||
|
||||
if _, err := s.GetReplica().Select(&teams, "SELECT * FROM Teams WHERE Name LIKE :Term OR DisplayName LIKE :Term ORDER BY DisplayName, Name LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Term": term + "%", "Limit": perPage, "Offset": offset}); err != nil {
|
||||
return nil, 0, model.NewAppError("SqlTeamStore.SearchAllPage", "store.sql_team.search_all_team.app_error", nil, "term="+term+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
totalCount, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE Name LIKE :Term OR DisplayName LIKE :Term", map[string]interface{}{"Term": term + "%"})
|
||||
if err != nil {
|
||||
return nil, 0, model.NewAppError("SqlTeamStore.SearchAllPage", "store.sql_team.search_all_team.app_error", nil, "term="+term+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return teams, totalCount, nil
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) SearchOpen(term string) ([]*model.Team, *model.AppError) {
|
||||
var teams []*model.Team
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ type TeamStore interface {
|
||||
Get(id string) (*model.Team, *model.AppError)
|
||||
GetByName(name string) (*model.Team, *model.AppError)
|
||||
SearchAll(term string) ([]*model.Team, *model.AppError)
|
||||
SearchAllPaged(term string, page int, perPage int) ([]*model.Team, int64, *model.AppError)
|
||||
SearchOpen(term string) ([]*model.Team, *model.AppError)
|
||||
SearchPrivate(term string) ([]*model.Team, *model.AppError)
|
||||
GetAll() ([]*model.Team, *model.AppError)
|
||||
|
||||
@@ -908,6 +908,38 @@ func (_m *TeamStore) SearchAll(term string) ([]*model.Team, *model.AppError) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchAllPaged provides a mock function with given fields: term, page, perPage
|
||||
func (_m *TeamStore) SearchAllPaged(term string, page int, perPage int) ([]*model.Team, int64, *model.AppError) {
|
||||
ret := _m.Called(term, page, perPage)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.Team); ok {
|
||||
r0 = rf(term, page, perPage)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 int64
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) int64); ok {
|
||||
r1 = rf(term, page, perPage)
|
||||
} else {
|
||||
r1 = ret.Get(1).(int64)
|
||||
}
|
||||
|
||||
var r2 *model.AppError
|
||||
if rf, ok := ret.Get(2).(func(string, int, int) *model.AppError); ok {
|
||||
r2 = rf(term, page, perPage)
|
||||
} else {
|
||||
if ret.Get(2) != nil {
|
||||
r2 = ret.Get(2).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// SearchOpen provides a mock function with given fields: term
|
||||
func (_m *TeamStore) SearchOpen(term string) ([]*model.Team, *model.AppError) {
|
||||
ret := _m.Called(term)
|
||||
|
||||
Reference in New Issue
Block a user