feat: add server-side pagination (#312)

Signed-off-by: “seriouszyx” <seriouszyx@foxmail.com>
This commit is contained in:
Yixiang Zhao
2021-11-06 11:32:22 +08:00
committed by GitHub
parent 7520b71198
commit b1db47bad1
28 changed files with 444 additions and 103 deletions

View File

@ -48,6 +48,15 @@ type Application struct {
SigninHtml string `xorm:"mediumtext" json:"signinHtml"`
}
func GetApplicationCount(owner string) int {
count, err := adapter.Engine.Count(&Application{Owner: owner})
if err != nil {
panic(err)
}
return int(count)
}
func GetApplications(owner string) []*Application {
applications := []*Application{}
err := adapter.Engine.Desc("created_time").Find(&applications, &Application{Owner: owner})
@ -58,6 +67,16 @@ func GetApplications(owner string) []*Application {
return applications
}
func GetPaginationApplications(owner string, offset, limit int) []*Application {
applications := []*Application{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&applications, &Application{Owner: owner})
if err != nil {
panic(err)
}
return applications
}
func getProviderMap(owner string) map[string]*Provider {
providers := GetProviders(owner)
m := map[string]*Provider{}

View File

@ -33,6 +33,15 @@ type Organization struct {
DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
}
func GetOrganizationCount(owner string) int {
count, err := adapter.Engine.Count(&Organization{Owner: owner})
if err != nil {
panic(err)
}
return int(count)
}
func GetOrganizations(owner string) []*Organization {
organizations := []*Organization{}
err := adapter.Engine.Desc("created_time").Find(&organizations, &Organization{Owner: owner})
@ -43,6 +52,16 @@ func GetOrganizations(owner string) []*Organization {
return organizations
}
func GetPaginationOrganizations(owner string, offset, limit int) []*Organization {
organizations := []*Organization{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&organizations, &Provider{Owner: owner})
if err != nil {
panic(err)
}
return organizations
}
func getOrganization(owner string, name string) *Organization {
if owner == "" || name == "" {
return nil
@ -57,7 +76,7 @@ func getOrganization(owner string, name string) *Organization {
if existed {
return &organization
}
return nil
}

View File

@ -64,6 +64,15 @@ func getMaskedProvider(provider *Provider) *Provider {
return p
}
func GetProviderCount(owner string) int {
count, err := adapter.Engine.Count(&Provider{Owner: owner})
if err != nil {
panic(err)
}
return int(count)
}
func GetProviders(owner string) []*Provider {
providers := []*Provider{}
err := adapter.Engine.Desc("created_time").Find(&providers, &Provider{Owner: owner})
@ -74,6 +83,16 @@ func GetProviders(owner string) []*Provider {
return providers
}
func GetPaginationProviders(owner string, offset, limit int) []*Provider {
providers := []*Provider{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&providers, &Provider{Owner: owner})
if err != nil {
panic(err)
}
return providers
}
func getProvider(owner string, name string) *Provider {
if owner == "" || name == "" {
return nil

View File

@ -54,6 +54,16 @@ func GetRecords() []*Records {
return records
}
func GetPaginationRecords(offset, limit int) []*Records {
records := []*Records{}
err := adapter.Engine.Desc("id").Limit(limit, offset).Find(&records)
if err != nil {
panic(err)
}
return records
}
func GetRecordsByField(record *Records) []*Records {
records := []*Records{}
err := adapter.Engine.Find(&records, record)

View File

@ -38,6 +38,15 @@ type Resource struct {
Url string `xorm:"varchar(1000)" json:"url"`
}
func GetResourceCount(owner string, user string) int {
count, err := adapter.Engine.Count(&Resource{Owner: owner, User: user})
if err != nil {
panic(err)
}
return int(count)
}
func GetResources(owner string, user string) []*Resource {
if owner == "built-in" {
owner = ""
@ -53,6 +62,21 @@ func GetResources(owner string, user string) []*Resource {
return resources
}
func GetPaginationResources(owner, user string, offset, limit int) []*Resource {
if owner == "built-in" {
owner = ""
user = ""
}
resources := []*Resource{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&resources, &Resource{Owner: owner, User: user})
if err != nil {
panic(err)
}
return resources
}
func getResource(owner string, name string) *Resource {
resource := Resource{Owner: owner, Name: name}
existed, err := adapter.Engine.Get(&resource)

View File

@ -49,6 +49,15 @@ type TokenWrapper struct {
Scope string `json:"scope"`
}
func GetTokenCount(owner string) int {
count, err := adapter.Engine.Count(&Token{Owner: owner})
if err != nil {
panic(err)
}
return int(count)
}
func GetTokens(owner string) []*Token {
tokens := []*Token{}
err := adapter.Engine.Desc("created_time").Find(&tokens, &Token{Owner: owner})
@ -59,6 +68,16 @@ func GetTokens(owner string) []*Token {
return tokens
}
func GetPaginationTokens(owner string, offset, limit int) []*Token {
tokens := []*Token{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&tokens, &Token{Owner: owner})
if err != nil {
panic(err)
}
return tokens
}
func getToken(owner string, name string) *Token {
if owner == "" || name == "" {
return nil
@ -73,7 +92,7 @@ func getToken(owner string, name string) *Token {
if existed {
return &token
}
return nil
}
@ -87,7 +106,7 @@ func getTokenByCode(code string) *Token {
if existed {
return &token
}
return nil
}

View File

@ -72,6 +72,15 @@ type User struct {
Properties map[string]string `json:"properties"`
}
func GetGlobalUserCount() int {
count, err := adapter.Engine.Count(&User{})
if err != nil {
panic(err)
}
return int(count)
}
func GetGlobalUsers() []*User {
users := []*User{}
err := adapter.Engine.Desc("created_time").Find(&users)
@ -82,6 +91,25 @@ func GetGlobalUsers() []*User {
return users
}
func GetPaginationGlobalUsers(offset, limit int) []*User {
users := []*User{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&users)
if err != nil {
panic(err)
}
return users
}
func GetUserCount(owner string) int {
count, err := adapter.Engine.Count(&User{Owner: owner})
if err != nil {
panic(err)
}
return int(count)
}
func GetUsers(owner string) []*User {
users := []*User{}
err := adapter.Engine.Desc("created_time").Find(&users, &User{Owner: owner})
@ -92,6 +120,16 @@ func GetUsers(owner string) []*User {
return users
}
func GetPaginationUsers(owner string, offset, limit int) []*User {
users := []*User{}
err := adapter.Engine.Desc("created_time").Limit(limit, offset).Find(&users, &User{Owner: owner})
if err != nil {
panic(err)
}
return users
}
func getUser(owner string, name string) *User {
if owner == "" || name == "" {
return nil