diff options
author | Ethan Koenig <etk39@cornell.edu> | 2016-12-23 20:53:11 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-24 09:53:11 +0800 |
commit | 8a4161c72335900407b8f111027ad9ed53c0b631 (patch) | |
tree | ddbb149b5f78d5a3ebf91db1a079ac4be3cc064b /models | |
parent | 25b5ffb6af390eac8d4a76c134379fd1ae88a423 (diff) | |
download | gitea-8a4161c72335900407b8f111027ad9ed53c0b631.tar.gz gitea-8a4161c72335900407b8f111027ad9ed53c0b631.zip |
API Endpoint for watching (#191)
Diffstat (limited to 'models')
-rw-r--r-- | models/user.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go index 1b8ebce432..1b645a5285 100644 --- a/models/user.go +++ b/models/user.go @@ -1241,3 +1241,18 @@ func GetStarredRepos(userID int64, private bool) ([]*Repository, error) { } return repos, nil } + +// GetWatchedRepos returns the repos watched by a particular user +func GetWatchedRepos(userID int64, private bool) ([]*Repository, error) { + sess := x.Where("watch.user_id=?", userID). + Join("LEFT", "watch", "`repository`.id=`watch`.repo_id") + if !private { + sess = sess.And("is_private=?", false) + } + repos := make([]*Repository, 0, 10) + err := sess.Find(&repos) + if err != nil { + return nil, err + } + return repos, nil +} |