You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
836 B
42 lines
836 B
5 years ago
|
class SubjectSearchService < ApplicationService
|
||
|
include ElasticsearchAble
|
||
|
|
||
|
attr_reader :params
|
||
|
|
||
|
def initialize(params)
|
||
|
@params = params
|
||
|
end
|
||
|
|
||
|
def call
|
||
|
# 全部实训/我的实训
|
||
|
type = params[:type] || "all"
|
||
|
|
||
|
if type == "mine"
|
||
|
@subjects = User.current.shixuns.visible.unhidden
|
||
|
else
|
||
|
@subjects = Subject.visible.unhidden
|
||
|
end
|
||
|
|
||
|
Subject.search(keyword, search_options)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def search_options
|
||
|
model_options = {
|
||
|
includes: [ user: { user_extension: :school } ]
|
||
|
}
|
||
|
model_options.merge!(where: { id: @subjects.pluck(:id) })
|
||
|
model_options.merge!(order: {sort_type => sort_str})
|
||
|
model_options.merge!(default_options)
|
||
|
model_options
|
||
|
end
|
||
|
|
||
|
def sort_str
|
||
|
params[:order] || "desc"
|
||
|
end
|
||
|
|
||
|
def sort_type
|
||
|
params[:sort] || "myshixuns_count"
|
||
|
end
|
||
|
end
|