aboutsummaryrefslogtreecommitdiffstats
path: root/models/star.go
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2017-02-07 19:54:16 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-07 19:54:16 +0800
commitb13232f52454b72c414e8bf686daccee712346e1 (patch)
treed83cba64b231aa17853cf9c135760847cb5b072f /models/star.go
parentceae143e78dabe9c5ef6bafff739aa487f79ca70 (diff)
downloadgitea-b13232f52454b72c414e8bf686daccee712346e1.tar.gz
gitea-b13232f52454b72c414e8bf686daccee712346e1.zip
feat: support paginater on star tab of user profile. (#845)
Diffstat (limited to 'models/star.go')
-rw-r--r--models/star.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/models/star.go b/models/star.go
index fd08c61fa6..39f6eac1f0 100644
--- a/models/star.go
+++ b/models/star.go
@@ -71,16 +71,26 @@ func (repo *Repository) GetStargazers(page int) ([]*User, error) {
}
// GetStarredRepos returns the repos the user starred.
-func (u *User) GetStarredRepos(private bool) (repos []*Repository, err error) {
+func (u *User) GetStarredRepos(private bool, page, pageSize int, orderBy string) (repos []*Repository, err error) {
+ if len(orderBy) == 0 {
+ orderBy = "star.id"
+ }
sess := x.
Join("INNER", "star", "star.repo_id = repository.id").
Where("star.uid = ?", u.ID).
- Desc("star.id")
+ Desc(orderBy)
if !private {
sess = sess.And("is_private = ?", false)
}
+ if page <= 0 {
+ page = 1
+ }
+ sess.Limit(pageSize, (page-1)*pageSize)
+
+ repos = make([]*Repository, 0, pageSize)
+
if err = sess.Find(&repos); err != nil {
return
}
@@ -93,3 +103,16 @@ func (u *User) GetStarredRepos(private bool) (repos []*Repository, err error) {
return
}
+
+// GetStarredRepoCount returns the numbers of repo the user starred.
+func (u *User) GetStarredRepoCount(private bool) (int64, error) {
+ sess := x.
+ Join("INNER", "star", "star.repo_id = repository.id").
+ Where("star.uid = ?", u.ID)
+
+ if !private {
+ sess = sess.And("is_private = ?", false)
+ }
+
+ return sess.Count(&Repository{})
+}