fixed 个人项目列表条件增加标签名查询

This commit is contained in:
xxq250 2024-08-29 16:18:59 +08:00
parent 9f269189a4
commit 39f234cc06
3 changed files with 12 additions and 6 deletions

View File

@ -43,11 +43,11 @@ class ProjectsController < ApplicationController
category_id = params[:category_id]
@total_count =
if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
if category_id.blank? && params[:search].blank? && params[:topic_id].blank? && params[:topic_name].blank?
# 默认查询时count性能问题处理
not_category_count = Project.where(project_category_id: nil).count
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + not_category_count
elsif params[:search].present? || params[:topic_id].present?
elsif params[:search].present? || params[:topic_id].present? || params[:topic_name].present?
@projects.total_count
else
cate = ProjectCategory.find_by(id: category_id)

View File

@ -77,10 +77,7 @@ class Projects::ListQuery < ApplicationQuery
end
def by_project_topic(items)
if params[:topic_name].present? && @current_user_id.present?
Project.visible.where(status: 1).with_project_topic_name(params[:topic_name].to_s.split(","))
.or(Project.is_private.with_project_topic_name(params[:topic_name].to_s.split(",")).where(user_id: @current_user_id))
elsif params[:topic_name].present?
if params[:topic_name].present?
items.with_project_topic_name(params[:topic_name].to_s.split(","))
else
items.with_project_topic(params[:topic_id])

View File

@ -20,6 +20,7 @@ class Users::ProjectService
projects = category_filter(projects)
projects = status_filter(projects)
projects = by_project_topic(projects)
custom_sort(projects, params[:sort_by], params[:sort_direction])
end
@ -45,6 +46,14 @@ class Users::ProjectService
end
end
def by_project_topic(items)
if params[:topic_name].present?
items.with_project_topic_name(params[:topic_name].to_s.split(","))
else
items.with_project_topic(params[:topic_id])
end
end
def self_or_admin?
User.current.id == user.id || User.current.admin?
end