|
|
|
@@ -1,7 +1,7 @@ |
|
|
|
class Api::V1::Users::Projects::ListService < ApplicationService |
|
|
|
include ActiveModel::Model |
|
|
|
|
|
|
|
attr_reader :observe_user, :category, :is_public, :project_type, :sort_by, :sort_direction, :search, :current_user |
|
|
|
attr_reader :observe_user, :category, :is_public, :project_type, :sort_by, :sort_direction, :search, :start_at, :end_at, :current_user |
|
|
|
attr_accessor :queried_projects |
|
|
|
|
|
|
|
validates :category, inclusion: {in: %w(all join created manage watched forked), message: "请输入正确的Category"} |
|
|
|
@@ -18,6 +18,8 @@ class Api::V1::Users::Projects::ListService < ApplicationService |
|
|
|
@sort_by = params[:sort_by] || 'updated_on' |
|
|
|
@sort_direction = params[:sort_direction] || 'desc' |
|
|
|
@search = params[:search] |
|
|
|
@start_at = params[:start_at] |
|
|
|
@end_at = params[:end_at] |
|
|
|
@current_user = current_user |
|
|
|
end |
|
|
|
|
|
|
|
@@ -53,10 +55,16 @@ class Api::V1::Users::Projects::ListService < ApplicationService |
|
|
|
projects = Project.from("( #{normal_projects} UNION #{org_projects} ) AS projects").distinct |
|
|
|
when 'watched' |
|
|
|
projects = projects.where.not(user_id: observe_user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id}) |
|
|
|
projects = projects.joins(:watchers).where("watchers.created_at > ? and watchers.created_at < ?", start_at, end_at) if start_at.present? && end_at.present? |
|
|
|
when 'only_watched' |
|
|
|
projects = projects.where.joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id}) |
|
|
|
projects = projects.joins(:watchers).where("watchers.created_at > ? and watchers.created_at < ?", start_at, end_at) if start_at.present? && end_at.present? |
|
|
|
when 'forked' |
|
|
|
fork_ids = observe_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) |
|
|
|
if start_at.present? && end_at.present? |
|
|
|
fork_ids = observe_user.fork_users.where("created_at > ? and created_at < ?", start_at, end_at).select(:id, :fork_project_id).pluck(:fork_project_id) |
|
|
|
else |
|
|
|
fork_ids = observe_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) |
|
|
|
end |
|
|
|
projects = projects.where(id: fork_ids) |
|
|
|
else |
|
|
|
normal_projects = projects.members_projects(observe_user.id).to_sql |
|
|
|
|