forgeplus/app/queries/projects/list_query.rb

22 lines
620 B
Ruby
Raw Permalink Normal View History

2020-03-09 00:40:16 +08:00
class Projects::ListQuery < ApplicationQuery
include CustomSortable
attr_reader :params
sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc
def initialize(params)
@params = params
end
def call
2020-03-20 13:10:25 +08:00
scope = Project.visible.like(params[:search])
2020-03-09 00:40:16 +08:00
.with_project_type(params[:project_type])
.with_project_category(params[:category_id])
.with_project_language(params[:language_id])
2020-03-19 17:16:25 +08:00
.includes(:project_category, :project_language, :owner)
2020-03-09 00:40:16 +08:00
custom_sort(scope, params[:sort_by], params[:sort_direction])
end
end