diff options
Diffstat (limited to 'models/packages/container/search.go')
-rw-r--r-- | models/packages/container/search.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/models/packages/container/search.go b/models/packages/container/search.go index a3409fe743..e4a5a53848 100644 --- a/models/packages/container/search.go +++ b/models/packages/container/search.go @@ -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) |