API Endpoint for watching (#191)

This commit is contained in:
Ethan Koenig 2016-12-23 20:53:11 -05:00 committed by Lunny Xiao
parent 25b5ffb6af
commit 8a4161c723
3 changed files with 147 additions and 0 deletions

View file

@ -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
}