<commit_before>class Admin::CourseSubjectController < Admin::AdminController
  include Admin::ImportHelper

  def index

    if params[:course_id]
      @course_subjects = CourseSubject.where(course_id: params[:course_id]).order(:course_id)
    else
      @course_subjects = CourseSubject.all.includes(:course_id)
    end
    @courses = Course.all
  end

  def import

    begin
      response = request_suap_api({url: 'https://suap.ifpb.edu.br/edu/api/receber_componentes_curriculares/',
      data: course_subject_params})

      if not response['erro'].nil? or response.empty?
        raise 'ImportError'
      end

      response.each do |pk, subject|
        db_subject = CourseSubject.find_or_create_by(id: pk.to_i)
        db_subject.initials = subject['sigla']
        db_subject.description = subject['descricao']
        db_subject.course_id = course_subject_params[:id_curso].to_i
        db_subject.semester = subject['periodo'].to_i
        db_subject.save
      end

      flash[:success] = "Foram importadas #{response.length} disciplinas com sucesso"<commit_msg>Ajustada controller das disciplinas<commit_after>class Admin::CourseSubjectController < Admin::AdminController
  include Admin::ImportHelper

  def index

    if params[:course_id]
      @course_subjects = CourseSubject.where(course_id: params[:course_id]).order(:course_id)
    else
      @course_subjects = CourseSubject.all.includes(:course)
    end
    @courses = Course.all
  end

  def import

    begin
      response = request_suap_api({url: 'https://suap.ifpb.edu.br/edu/api/receber_componentes_curriculares/',
      data: course_subject_params})

      if not response['erro'].nil? or response.empty?
        raise 'ImportError'
      end

      response.each do |pk, subject|
        db_subject = CourseSubject.find_or_create_by(id: pk.to_i)
        db_subject.initials = subject['sigla']
        db_subject.description = subject['descricao']
        db_subject.course_id = course_subject_params[:id_curso].to_i
        db_subject.semester = subject['periodo'].to_i
        db_subject.save
      end

      flash[:success] = "Foram importadas #{response.length} disciplinas com sucesso"
{'fraction_non_alphanumeric': 0.10298850574712644, 'fraction_numerical': 0.0, 'mean_word_length': 3.477366255144033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6980786', 'n_tokens_mistral': 687, 'n_tokens_neox': 666, 'n_words': 120}