1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

feat: support search bar on star tab of user profile. (#917)

* feat: support search bar on star tab of user profile.

* fix: update testing.

* fix: Using loadAttributes

* fix: remove empty line.

* remove LOWER

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-02-14 15:28:22 +08:00
committed by Lunny Xiao
parent 7eb8daffa3
commit 23aba523b5
8 changed files with 109 additions and 76 deletions

View File

@@ -1778,13 +1778,15 @@ type SearchRepoOptions struct {
Searcher *User //ID of the person who's seeking
OrderBy string
Private bool // Include private repositories in results
Starred bool
Page int
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
}
// SearchRepositoryByName takes keyword and part of repository name to search,
// it returns results in given range and number of total results.
func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int64, _ error) {
func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ int64, _ error) {
var sess *xorm.Session
if len(opts.Keyword) == 0 {
return repos, 0, nil
}
@@ -1796,9 +1798,17 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int
repos = make([]*Repository, 0, opts.PageSize)
if opts.Starred && opts.OwnerID > 0 {
sess = x.
Join("INNER", "star", "star.repo_id = repository.id").
Where("star.uid = ?", opts.OwnerID).
And("lower_name LIKE ?", "%"+opts.Keyword+"%")
} else {
sess = x.Where("lower_name LIKE ?", "%"+opts.Keyword+"%")
}
// Append conditions
sess := x.Where("LOWER(lower_name) LIKE ?", "%"+opts.Keyword+"%")
if opts.OwnerID > 0 {
if !opts.Starred && opts.OwnerID > 0 {
sess.And("owner_id = ?", opts.OwnerID)
}
if !opts.Private {
@@ -1831,10 +1841,20 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int
return nil, 0, fmt.Errorf("Count: %v", err)
}
return repos, count, sess.
if err = sess.
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
OrderBy(opts.OrderBy).
Find(&repos)
Find(&repos); err != nil {
return nil, 0, fmt.Errorf("Repo: %v", err)
}
if opts.Starred {
if err = repos.loadAttributes(x); err != nil {
return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
}
}
return repos, count, nil
}
// DeleteRepositoryArchives deletes all repositories' archives.