add search bank slim api

dev_course
p31729568 6 years ago
parent 2f5d7ca451
commit a42ce8c024

@ -994,6 +994,20 @@ class CoursesController < ApplicationController
end
end
def search_slim
courses = current_user.manage_courses.not_deleted.processing
keyword = params[:keyword].to_s.strip
if keyword.present?
courses = courses.where('name LIKE ?', "%#{keyword}%")
end
count = courses.count
courses = paginate(courses)
render_ok(count: count, courses: courses.select(:id, :name).as_json)
end
private
# Use callbacks to share common setup or constraints between actions.

@ -61,6 +61,8 @@ class Course < ApplicationRecord
scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) }
scope :ended, ->(is_end = true) { where(is_end: is_end) }
scope :processing, -> { where(is_end: false) }
scope :not_deleted, -> { where(is_delete: false) }
scope :deleted, ->(is_delete = 1) { where(is_delete: is_delete) }
scope :by_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) }
scope :by_keywords, lambda { |keywords|

@ -303,6 +303,7 @@ Rails.application.routes.draw do
post 'search_course_list'
get 'board_list'
get 'mine'
get 'search_slim'
end
resources :polls, only:[:index,:new,:create] do

Loading…
Cancel
Save