2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Used to filter project topics by a set of params
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# params:
|
|
|
|
# search: string
|
|
|
|
module Projects
|
|
|
|
class TopicsFinder
|
|
|
|
def initialize(params: {})
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2022-05-07 20:08:51 +05:30
|
|
|
topics = Projects::Topic.order_by_non_private_projects_count
|
2022-08-27 11:52:29 +05:30
|
|
|
topics = by_without_projects(topics)
|
2021-11-18 22:05:49 +05:30
|
|
|
by_search(topics)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :current_user, :params
|
|
|
|
|
|
|
|
def by_search(topics)
|
|
|
|
return topics unless params[:search].present?
|
|
|
|
|
|
|
|
topics.search(params[:search]).reorder_by_similarity(params[:search])
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
def by_without_projects(topics)
|
|
|
|
return topics unless params[:without_projects]
|
|
|
|
|
|
|
|
topics.without_assigned_projects
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|