class Admins::LaboratorySubjectsController < Admins::BaseController helper_method :current_laboratory, :current_laboratory_subject def index laboratory_subjects = Admins::LaboratorySubjectQuery.call(current_laboratory, params) includes_tables = { subject: [:repertoire, :subject_level_system, user: {user_extension: :school}] } @laboratory_subjects = paginate(laboratory_subjects.includes(includes_tables)) end def create subject_ids = Array.wrap(params[:subject_ids]) subject_ids = Subject.where(id: subject_ids).pluck(:id) exist_subject_id = current_laboratory.laboratory_subjects.where(subject_id: subject_ids).pluck(:subject_id) LaboratorySubject.bulk_insert(*%i[subject_id laboratory_id created_at updated_at]) do |worker| (subject_ids - exist_subject_id).each do |subject_id| worker.add(subject_id: subject_id, laboratory_id: current_laboratory.id) end end render_ok end def homepage current_laboratory_subject.update!(homepage: true) render_ok end def cancel_homepage current_laboratory_subject.update!(homepage: false) render_ok end private def current_laboratory @_current_laboratory ||= Laboratory.find(params[:laboratory_id]) end def current_laboratory_subject @_current_laboratory_subject ||= current_laboratory.laboratory_subjects.find(params[:id]) end end