class Ecs::CourseManagersController < Ecs::CourseBaseController
  skip_before_action :check_user_permission!, only: [:create, :destroy]
  before_action :check_major_manager_permission!, only: [:create, :destroy]

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

  def destroy
    # params[:id] 为 user_id
    manager = current_course.ec_course_users.find_by(user_id: params[:id])
    return render_error('不存在该课程管理员！') if manager.blank?

    manager.destroy!

    render_ok
  end
end