mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Allow package version sorting (#21453)
This commit is contained in:
parent
63ebb53fd5
commit
876ee8c3cd
6 changed files with 58 additions and 17 deletions
|
@ -165,6 +165,7 @@ type ImageTagsSearchOptions struct {
|
|||
PackageID int64
|
||||
Query string
|
||||
IsTagged bool
|
||||
Sort packages.VersionSort
|
||||
db.Paginator
|
||||
}
|
||||
|
||||
|
@ -195,12 +196,26 @@ func (opts *ImageTagsSearchOptions) toConds() builder.Cond {
|
|||
return cond
|
||||
}
|
||||
|
||||
func (opts *ImageTagsSearchOptions) configureOrderBy(e db.Engine) {
|
||||
switch opts.Sort {
|
||||
case packages.SortVersionDesc:
|
||||
e.Desc("package_version.version")
|
||||
case packages.SortVersionAsc:
|
||||
e.Asc("package_version.version")
|
||||
case packages.SortCreatedAsc:
|
||||
e.Asc("package_version.created_unix")
|
||||
default:
|
||||
e.Desc("package_version.created_unix")
|
||||
}
|
||||
}
|
||||
|
||||
// SearchImageTags gets a sorted list of the tags of an image
|
||||
func SearchImageTags(ctx context.Context, opts *ImageTagsSearchOptions) ([]*packages.PackageVersion, int64, error) {
|
||||
sess := db.GetEngine(ctx).
|
||||
Join("INNER", "package", "package.id = package_version.package_id").
|
||||
Where(opts.toConds()).
|
||||
Desc("package_version.created_unix")
|
||||
Where(opts.toConds())
|
||||
|
||||
opts.configureOrderBy(sess)
|
||||
|
||||
if opts.Paginator != nil {
|
||||
sess = db.SetSessionPagination(sess, opts)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue