forgeplus/app/queries/projects/list_query.rb

30 lines
822 B
Ruby
Raw Normal View History

2020-03-09 00:40:16 +08:00
class Projects::ListQuery < ApplicationQuery
include CustomSortable
2021-09-07 17:19:38 +08:00
attr_reader :params, :current_user_id
2020-03-09 00:40:16 +08:00
sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc
2021-09-07 17:19:38 +08:00
def initialize(params, current_user_id=nil)
2020-03-09 00:40:16 +08:00
@params = params
2021-09-07 17:19:38 +08:00
@current_user_id = current_user_id
2020-03-09 00:40:16 +08:00
end
def call
2021-09-18 10:38:07 +08:00
q = Project.visible.by_name_or_identifier(params[:search])
2020-05-09 15:51:40 +08:00
scope = q
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-09 00:40:16 +08:00
2020-04-10 19:46:04 +08:00
sort = params[:sort_by] || "updated_on"
2020-04-10 19:45:32 +08:00
sort_direction = params[:sort_direction] || "desc"
2020-05-08 18:33:37 +08:00
custom_sort(scope, sort, sort_direction)
# scope = scope.reorder("projects.#{sort} #{sort_direction}")
# scope
2020-03-09 00:40:16 +08:00
end
end