You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_repo.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "code.gitea.io/gitea/models/db"
  7. )
  8. // GetStarredRepos returns the repos starred by a particular user
  9. func GetStarredRepos(userID int64, private bool, listOptions db.ListOptions) ([]*Repository, error) {
  10. sess := db.GetEngine(db.DefaultContext).Where("star.uid=?", userID).
  11. Join("LEFT", "star", "`repository`.id=`star`.repo_id")
  12. if !private {
  13. sess = sess.And("is_private=?", false)
  14. }
  15. if listOptions.Page != 0 {
  16. sess = db.SetSessionPagination(sess, &listOptions)
  17. repos := make([]*Repository, 0, listOptions.PageSize)
  18. return repos, sess.Find(&repos)
  19. }
  20. repos := make([]*Repository, 0, 10)
  21. return repos, sess.Find(&repos)
  22. }
  23. // GetWatchedRepos returns the repos watched by a particular user
  24. func GetWatchedRepos(userID int64, private bool, listOptions db.ListOptions) ([]*Repository, int64, error) {
  25. sess := db.GetEngine(db.DefaultContext).Where("watch.user_id=?", userID).
  26. And("`watch`.mode<>?", WatchModeDont).
  27. Join("LEFT", "watch", "`repository`.id=`watch`.repo_id")
  28. if !private {
  29. sess = sess.And("is_private=?", false)
  30. }
  31. if listOptions.Page != 0 {
  32. sess = db.SetSessionPagination(sess, &listOptions)
  33. repos := make([]*Repository, 0, listOptions.PageSize)
  34. total, err := sess.FindAndCount(&repos)
  35. return repos, total, err
  36. }
  37. repos := make([]*Repository, 0, 10)
  38. total, err := sess.FindAndCount(&repos)
  39. return repos, total, err
  40. }