mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-09-06 22:33:14 +00:00
Create a new function to build search repository condition (#10858)
Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
This commit is contained in:
parent
48890ce546
commit
61f603cd8a
1 changed files with 13 additions and 6 deletions
|
@ -190,12 +190,8 @@ const (
|
||||||
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
|
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SearchRepository returns repositories based on search options,
|
// SearchRepositoryCondition creates a query condition according search repository options
|
||||||
// it returns results in given range and number of total results.
|
func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
|
||||||
func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
|
|
||||||
if opts.Page <= 0 {
|
|
||||||
opts.Page = 1
|
|
||||||
}
|
|
||||||
var cond = builder.NewCond()
|
var cond = builder.NewCond()
|
||||||
|
|
||||||
if opts.Private {
|
if opts.Private {
|
||||||
|
@ -298,6 +294,17 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
|
||||||
if opts.Actor != nil && opts.Actor.IsRestricted {
|
if opts.Actor != nil && opts.Actor.IsRestricted {
|
||||||
cond = cond.And(accessibleRepositoryCondition(opts.Actor))
|
cond = cond.And(accessibleRepositoryCondition(opts.Actor))
|
||||||
}
|
}
|
||||||
|
return cond
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchRepository returns repositories based on search options,
|
||||||
|
// it returns results in given range and number of total results.
|
||||||
|
func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
|
||||||
|
cond := SearchRepositoryCondition(opts)
|
||||||
|
|
||||||
|
if opts.Page <= 0 {
|
||||||
|
opts.Page = 1
|
||||||
|
}
|
||||||
|
|
||||||
if len(opts.OrderBy) == 0 {
|
if len(opts.OrderBy) == 0 {
|
||||||
opts.OrderBy = SearchOrderByAlphabetically
|
opts.OrderBy = SearchOrderByAlphabetically
|
||||||
|
|
Loading…
Reference in a new issue