diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2016-12-29 12:58:24 -0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-29 22:58:24 +0800 |
commit | b9928588834a9aad1771ba79f1d6638cdc29904a (patch) | |
tree | 790d6d87a1565076a1fd06d28618d465366b9350 /models/repo.go | |
parent | 2d1a1fce934cb87cc67b85083d342b14bb52b780 (diff) | |
download | gitea-b9928588834a9aad1771ba79f1d6638cdc29904a.tar.gz gitea-b9928588834a9aad1771ba79f1d6638cdc29904a.zip |
Tab on user profile to show starred repos (#519)
* Tab on user profile to show starred repos
* Make golint happy and use transactions on StarRepo function
* x -> sess
* Use sess.Close() instead of sess.Rollback()
* Add copyright
* Fix lint
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/models/repo.go b/models/repo.go index 33d84642df..ce9740f8c4 100644 --- a/models/repo.go +++ b/models/repo.go @@ -2146,66 +2146,6 @@ func NotifyWatchers(act *Action) error { return notifyWatchers(x, act) } -// _________ __ -// / _____// |______ _______ -// \_____ \\ __\__ \\_ __ \ -// / \| | / __ \| | \/ -// /_______ /|__| (____ /__| -// \/ \/ - -// Star contains the star information -type Star struct { - ID int64 `xorm:"pk autoincr"` - UID int64 `xorm:"UNIQUE(s)"` - RepoID int64 `xorm:"UNIQUE(s)"` -} - -// StarRepo star or unstar repository. -func StarRepo(userID, repoID int64, star bool) (err error) { - if star { - if IsStaring(userID, repoID) { - return nil - } - if _, err = x.Insert(&Star{UID: userID, RepoID: repoID}); err != nil { - return err - } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoID); err != nil { - return err - } - _, err = x.Exec("UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", userID) - } else { - if !IsStaring(userID, repoID) { - return nil - } - if _, err = x.Delete(&Star{0, userID, repoID}); err != nil { - return err - } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoID); err != nil { - return err - } - _, err = x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID) - } - return err -} - -// IsStaring checks if user has starred given repository. -func IsStaring(userID, repoID int64) bool { - has, _ := x.Get(&Star{0, userID, repoID}) - return has -} - -// GetStargazers returns the users who gave stars to this repository -func (repo *Repository) GetStargazers(page int) ([]*User, error) { - users := make([]*User, 0, ItemsPerPage) - sess := x. - Limit(ItemsPerPage, (page-1)*ItemsPerPage). - Where("star.repo_id=?", repo.ID) - if setting.UsePostgreSQL { - sess = sess.Join("LEFT", "star", `"user".id=star.uid`) - } else { - sess = sess.Join("LEFT", "star", "user.id=star.uid") - } - return users, sess.Find(&users) -} - // ___________ __ // \_ _____/__________| | __ // | __)/ _ \_ __ \ |/ / |