debian-mirror-gitlab/app/finders/packages/packages_finder.rb

36 lines
867 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
class PackagesFinder
2021-03-11 19:13:27 +05:30
include ::Packages::FinderHelper
2020-07-28 23:09:34 +05:30
def initialize(project, params = {})
@project = project
@params = params
params[:order_by] ||= 'created_at'
params[:sort] ||= 'asc'
end
def execute
2020-11-24 15:15:51 +05:30
packages = project.packages
.including_build_info
.including_project_route
.including_tags
2021-03-08 18:12:59 +05:30
packages = filter_with_version(packages)
2020-07-28 23:09:34 +05:30
packages = filter_by_package_type(packages)
packages = filter_by_package_name(packages)
2021-03-11 19:13:27 +05:30
packages = filter_by_status(packages)
2021-04-29 21:17:54 +05:30
order_packages(packages)
2020-07-28 23:09:34 +05:30
end
private
2021-03-11 19:13:27 +05:30
attr_reader :params, :project
2020-07-28 23:09:34 +05:30
def order_packages(packages)
packages.sort_by_attribute("#{params[:order_by]}_#{params[:sort]}")
end
end
end