summaryrefslogtreecommitdiff
path: root/app/finders/users_star_projects_finder.rb
blob: 49c4e087b4b23422762a3b77bf766f1845e4a239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

class UsersStarProjectsFinder
  include CustomAttributesFilter

  attr_accessor :params

  def initialize(project, params = {}, current_user: nil)
    @params = params
    @project = project
    @current_user = current_user
  end

  def execute
    stars = UsersStarProject.all
    stars = by_project(stars)
    stars = by_search(stars)
    stars = filter_visible_profiles(stars)

    stars
  end

  private

  def by_search(items)
    params[:search].present? ? items.search(params[:search]) : items
  end

  def by_project(items)
    items.by_project(@project)
  end

  def filter_visible_profiles(items)
    items.with_visible_profile(@current_user)
  end
end