debian-mirror-gitlab/app/finders/bulk_imports/imports_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
610 B
Ruby
Raw Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
module BulkImports
class ImportsFinder
2022-06-21 17:19:12 +05:30
def initialize(user:, params: {})
2021-09-30 23:02:18 +05:30
@user = user
2022-06-21 17:19:12 +05:30
@params = params
2021-09-30 23:02:18 +05:30
end
def execute
2022-06-21 17:19:12 +05:30
imports = filter_by_status(user.bulk_imports)
sort(imports)
2021-09-30 23:02:18 +05:30
end
private
attr_reader :user, :status
def filter_by_status(imports)
2022-06-21 17:19:12 +05:30
return imports unless BulkImport.all_human_statuses.include?(@params[:status])
2021-09-30 23:02:18 +05:30
2022-06-21 17:19:12 +05:30
imports.with_status(@params[:status])
end
def sort(imports)
return imports unless @params[:sort]
imports.order_by_created_at(@params[:sort])
2021-09-30 23:02:18 +05:30
end
end
end