mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-09 22:39:50 +08:00
init project
This commit is contained in:
23
app/queries/admins/laboratory_query.rb
Normal file
23
app/queries/admins/laboratory_query.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class Admins::LaboratoryQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
|
||||
sort_columns :id, default_by: :id, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
laboratories = Laboratory.all
|
||||
|
||||
keyword = strip_param(:keyword)
|
||||
if keyword.present?
|
||||
like_sql = 'schools.name LIKE :keyword OR laboratories.identifier LIKE :keyword'
|
||||
laboratories = laboratories.left_joins(:school).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
custom_sort laboratories, params[:sort_by], params[:sort_direction]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user