summaryrefslogtreecommitdiffstats
path: root/models/star.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/star.go')
-rw-r--r--models/star.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/models/star.go b/models/star.go
index f71d39ce2c..2d50a002d7 100644
--- a/models/star.go
+++ b/models/star.go
@@ -5,6 +5,7 @@
package models
import (
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
)
@@ -16,9 +17,13 @@ type Star struct {
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
}
+func init() {
+ db.RegisterModel(new(Star))
+}
+
// StarRepo or unstar repository.
func StarRepo(userID, repoID int64, star bool) error {
- sess := x.NewSession()
+ sess := db.DefaultContext().NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -60,17 +65,17 @@ func StarRepo(userID, repoID int64, star bool) error {
// IsStaring checks if user has starred given repository.
func IsStaring(userID, repoID int64) bool {
- return isStaring(x, userID, repoID)
+ return isStaring(db.DefaultContext().Engine(), userID, repoID)
}
-func isStaring(e Engine, userID, repoID int64) bool {
+func isStaring(e db.Engine, userID, repoID int64) bool {
has, _ := e.Get(&Star{UID: userID, RepoID: repoID})
return has
}
// GetStargazers returns the users that starred the repo.
func (repo *Repository) GetStargazers(opts ListOptions) ([]*User, error) {
- sess := x.Where("star.repo_id = ?", repo.ID).
+ sess := db.DefaultContext().Engine().Where("star.repo_id = ?", repo.ID).
Join("LEFT", "star", "`user`.id = star.uid")
if opts.Page > 0 {
sess = setSessionPagination(sess, &opts)
@@ -88,7 +93,7 @@ func (u *User) GetStarredRepos(private bool, page, pageSize int, orderBy string)
if len(orderBy) == 0 {
orderBy = "updated_unix DESC"
}
- sess := x.
+ sess := db.DefaultContext().Engine().
Join("INNER", "star", "star.repo_id = repository.id").
Where("star.uid = ?", u.ID).
OrderBy(orderBy)
@@ -108,7 +113,7 @@ func (u *User) GetStarredRepos(private bool, page, pageSize int, orderBy string)
return
}
- if err = repos.loadAttributes(x); err != nil {
+ if err = repos.loadAttributes(db.DefaultContext().Engine()); err != nil {
return
}
@@ -117,7 +122,7 @@ func (u *User) GetStarredRepos(private bool, page, pageSize int, orderBy string)
// GetStarredRepoCount returns the numbers of repo the user starred.
func (u *User) GetStarredRepoCount(private bool) (int64, error) {
- sess := x.
+ sess := db.DefaultContext().Engine().
Join("INNER", "star", "star.repo_id = repository.id").
Where("star.uid = ?", u.ID)