summaryrefslogtreecommitdiff
path: root/app/finders/abuse_reports_finder.rb
blob: 90d09a2d6ed2dc7b8d843e0bc79742486fc03d5b (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

class AbuseReportsFinder
  attr_reader :params, :reports

  def initialize(params = {})
    @params = params
    @reports = AbuseReport.all
  end

  def execute
    filter_reports

    reports.with_order_id_desc
      .with_users
      .page(params[:page])
  end

  private

  def filter_reports
    filter_by_user_id

    filter_by_status
    filter_by_category
  end

  def filter_by_status
    return unless params[:status].present?

    case params[:status]
    when 'open'
      @reports = @reports.open
    when 'closed'
      @reports = @reports.closed
    end
  end

  def filter_by_category
    return unless params[:category].present?

    @reports = @reports.by_category(params[:category])
  end

  def filter_by_user_id
    return unless params[:user_id].present?

    @reports = @reports.by_user_id(params[:user_id])
  end
end