forked from Gitlink/forgeplus
FIX update query projects api
This commit is contained in:
parent
0e9699885d
commit
83661dcf71
|
@ -11,20 +11,45 @@ class Projects::ListQuery < ApplicationQuery
|
|||
end
|
||||
|
||||
def call
|
||||
q = params[:pinned].present? ? Project.pinned : Project
|
||||
q = q.visible.by_name_or_identifier(params[:search])
|
||||
|
||||
scope = q
|
||||
.with_project_type(params[:project_type])
|
||||
.with_project_category(params[:category_id])
|
||||
.with_project_language(params[:language_id])
|
||||
collection = Project.all
|
||||
collection = filter_projects(collection)
|
||||
|
||||
sort = params[:sort_by] || "updated_on"
|
||||
sort_direction = params[:sort_direction] || "desc"
|
||||
|
||||
custom_sort(scope, sort, sort_direction)
|
||||
custom_sort(collection, sort, sort_direction)
|
||||
|
||||
# scope = scope.reorder("projects.#{sort} #{sort_direction}")
|
||||
# scope
|
||||
end
|
||||
|
||||
def filter_projects(collection)
|
||||
collection = by_pinned(collection)
|
||||
collection = by_search(collection)
|
||||
collection = by_project_type(collection)
|
||||
collection = by_project_category(collection)
|
||||
collection = by_project_language(collection)
|
||||
collection
|
||||
end
|
||||
|
||||
def by_search(items)
|
||||
items.visible.by_name_or_identifier(params[:search])
|
||||
end
|
||||
|
||||
def by_project_type(items)
|
||||
items.with_project_type(params[:project_type])
|
||||
end
|
||||
|
||||
def by_project_category(items)
|
||||
items.with_project_category(params[:category_id])
|
||||
end
|
||||
|
||||
def by_project_language(items)
|
||||
items.with_project_language(params[:language_id])
|
||||
end
|
||||
|
||||
def by_pinned(items)
|
||||
(params[:pinned].present? && params[:category_id].present?) ? items.pinned : items
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue