class Ecs::StudentsController < Ecs::BaseController
  before_action :check_major_manager_permission!, only: [:destroy, :import]

  def show
    students = current_year.ec_year_students

    @count    = students.count
    @students = paginate students
  end

  def destroy
    current_year.ec_year_students.where(id: params[:ids]).destroy_all
    render_ok
  end

  def import
    success_count = Ecs::ImportStudentService.call(current_year, params[:attachment_id])
    render_ok(success_count: success_count)
  rescue Ecs::ImportStudentService::Error => ex
    render_error(ex.message)
  end
end