2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
class ExportJobFinder
|
|
|
|
InvalidExportJobStatusError = Class.new(StandardError)
|
|
|
|
attr_reader :project, :params
|
|
|
|
|
|
|
|
def initialize(project, params = {})
|
|
|
|
@project = project
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
export_jobs = project.export_jobs
|
2021-04-29 21:17:54 +05:30
|
|
|
by_status(export_jobs)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def by_status(export_jobs)
|
|
|
|
return export_jobs unless params[:status]
|
|
|
|
raise InvalidExportJobStatusError, 'Invalid export job status' unless ProjectExportJob.state_machines[:status].states.map(&:name).include?(params[:status])
|
|
|
|
|
|
|
|
export_jobs.with_status(params[:status])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|