From 1f01f53c53ea75634f981611635be49c69e1920b Mon Sep 17 00:00:00 2001 From: SpaWn2KiLl Date: Fri, 24 Jan 2020 19:00:29 +0000 Subject: API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath --- models/org_team.go | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'models/org_team.go') diff --git a/models/org_team.go b/models/org_team.go index 0c0a1e7b79..214790703c 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -39,12 +39,16 @@ type Team struct { // SearchTeamOptions holds the search options type SearchTeamOptions struct { + ListOptions UserID int64 Keyword string OrgID int64 IncludeDesc bool - PageSize int - Page int +} + +// SearchMembersOptions holds the search options +type SearchMembersOptions struct { + ListOptions } // SearchTeam search for teams. Caller is responsible to check permissions. @@ -160,9 +164,13 @@ func (t *Team) getRepositories(e Engine) error { Find(&t.Repos) } -// GetRepositories returns all repositories in team of organization. -func (t *Team) GetRepositories() error { - return t.getRepositories(x) +// GetRepositories returns paginated repositories in team of organization. +func (t *Team) GetRepositories(opts *SearchTeamOptions) error { + if opts.Page == 0 { + return t.getRepositories(x) + } + + return t.getRepositories(opts.getPaginatedSession()) } func (t *Team) getMembers(e Engine) (err error) { @@ -170,9 +178,13 @@ func (t *Team) getMembers(e Engine) (err error) { return err } -// GetMembers returns all members in team of organization. -func (t *Team) GetMembers() (err error) { - return t.getMembers(x) +// GetMembers returns paginated members in team of organization. +func (t *Team) GetMembers(opts *SearchMembersOptions) (err error) { + if opts.Page == 0 { + return t.getMembers(x) + } + + return t.getMembers(opts.getPaginatedSession()) } // AddMember adds new membership of the team to the organization, @@ -642,7 +654,7 @@ func UpdateTeam(t *Team, authChanged bool, includeAllChanged bool) (err error) { // DeleteTeam deletes given team. // It's caller's responsibility to assign organization ID. func DeleteTeam(t *Team) error { - if err := t.GetRepositories(); err != nil { + if err := t.GetRepositories(&SearchTeamOptions{}); err != nil { return err } @@ -747,11 +759,14 @@ func GetTeamMembers(teamID int64) ([]*User, error) { return getTeamMembers(x, teamID) } -func getUserTeams(e Engine, userID int64) (teams []*Team, err error) { - return teams, e. +func getUserTeams(e Engine, userID int64, listOptions ListOptions) (teams []*Team, err error) { + sess := e. Join("INNER", "team_user", "team_user.team_id = team.id"). - Where("team_user.uid=?", userID). - Find(&teams) + Where("team_user.uid=?", userID) + if listOptions.Page != 0 { + sess = listOptions.setSessionPagination(sess) + } + return teams, sess.Find(&teams) } func getUserOrgTeams(e Engine, orgID, userID int64) (teams []*Team, err error) { @@ -778,8 +793,8 @@ func GetUserOrgTeams(orgID, userID int64) ([]*Team, error) { } // GetUserTeams returns all teams that user belongs across all organizations. -func GetUserTeams(userID int64) ([]*Team, error) { - return getUserTeams(x, userID) +func GetUserTeams(userID int64, listOptions ListOptions) ([]*Team, error) { + return getUserTeams(x, userID, listOptions) } // AddTeamMember adds new membership of given team to given organization, @@ -795,7 +810,7 @@ func AddTeamMember(team *Team, userID int64) error { } // Get team and its repositories. - if err := team.GetRepositories(); err != nil { + if err := team.GetRepositories(&SearchTeamOptions{}); err != nil { return err } -- cgit v1.2.3