class Ecs::MajorManagersController < Ecs::BaseController
  skip_before_action :check_user_permission!
  before_action :check_manager_permission!

  def create
    Ecs::CreateMajorManagerService.call(current_major_school, params[:user_ids])
    render_ok
  rescue Ecs::CreateMajorManagerService::Error => ex
    render_error(ex.message)
  end

  def destroy
    # params[:id] 为 user_id
    manager = current_major_school.ec_major_school_users.find_by(user_id: params[:id])
    return render_error('不存在该专业管理员！') if manager.blank?

    manager.destroy!

    render_ok
  end

  private

  def current_major_school
    @_ec_major_school ||= EcMajorSchool.find(params[:ec_major_school_id])
  end

  def current_school
    @_current_school ||= current_major_school.school
  end
end
