-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix NuGet search endpoints #25613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix NuGet search endpoints #25613
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
021d4f1
Fix NuGet search endpoints.
KN4CK3R 87e3e3d
Change BuilderDialect.
KN4CK3R 506f98e
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-nug…
KN4CK3R 457154f
Update xorm.
KN4CK3R 1a10eca
Update xorm builder.
KN4CK3R 0c8a2bb
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-nug…
KN4CK3R 6037bf2
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-nug…
KN4CK3R 69522c6
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-nug…
KN4CK3R edba4a6
Apply suggestions.
KN4CK3R 4e3038e
lint
KN4CK3R 46a2393
Merge branch 'main' of https://github.com/go-gitea/gitea into fix-nug…
KN4CK3R c047592
Merge branch 'main' into fix-nuget-search
GiteaBot 6f7092c
Merge branch 'main' into fix-nuget-search
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package nuget | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
packages_model "code.gitea.io/gitea/models/packages" | ||
|
||
"xorm.io/builder" | ||
) | ||
|
||
// SearchVersions gets all versions of packages matching the search options | ||
func SearchVersions(ctx context.Context, opts *packages_model.PackageSearchOptions) ([]*packages_model.PackageVersion, int64, error) { | ||
var cond builder.Cond = builder.Eq{ | ||
"package.is_internal": opts.IsInternal.IsTrue(), | ||
"package.owner_id": opts.OwnerID, | ||
"package.type": packages_model.TypeNuGet, | ||
} | ||
if opts.Name.Value != "" { | ||
if opts.Name.ExactMatch { | ||
cond = cond.And(builder.Eq{"package.lower_name": strings.ToLower(opts.Name.Value)}) | ||
} else { | ||
cond = cond.And(builder.Like{"package.lower_name", strings.ToLower(opts.Name.Value)}) | ||
} | ||
} | ||
KN4CK3R marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
e := db.GetEngine(ctx) | ||
|
||
total, err := e. | ||
Where(cond). | ||
Count(&packages_model.Package{}) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
inner := builder. | ||
Dialect(db.BuilderDialect(ctx)). | ||
Select("*"). | ||
From("package"). | ||
Where(cond). | ||
OrderBy("package.name ASC") | ||
if opts.Paginator != nil { | ||
skip, take := opts.GetSkipTake() | ||
inner = inner.Limit(take, skip) | ||
} | ||
|
||
sess := e. | ||
Where(opts.ToConds()). | ||
Table("package_version"). | ||
Join("INNER", inner, "package.id = package_version.package_id") | ||
|
||
pvs := make([]*packages_model.PackageVersion, 0, 10) | ||
return pvs, total, sess.Find(&pvs) | ||
} | ||
|
||
// CountPackages counts all packages matching the search options | ||
func CountPackages(ctx context.Context, opts *packages_model.PackageSearchOptions) (int64, error) { | ||
var cond builder.Cond = builder.Eq{ | ||
"package.is_internal": opts.IsInternal.IsTrue(), | ||
"package.owner_id": opts.OwnerID, | ||
"package.type": packages_model.TypeNuGet, | ||
} | ||
if opts.Name.Value != "" { | ||
if opts.Name.ExactMatch { | ||
cond = cond.And(builder.Eq{"package.lower_name": strings.ToLower(opts.Name.Value)}) | ||
} else { | ||
cond = cond.And(builder.Like{"package.lower_name", strings.ToLower(opts.Name.Value)}) | ||
} | ||
} | ||
|
||
return db.GetEngine(ctx). | ||
Where(cond). | ||
Count(&packages_model.Package{}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.