<commit_before>class Users::FavoriteCoursesController < ApplicationController
  include CourseManager

  before_action :authenticate_user!
  before_action :redis_state, only: [:show, :export]

  def show
    @courses = Course.show_favorite_courses(current_user.favorite_courses).includes(:entries, comments: :replies)
  end

  def create
    append_course(:favorite_courses, params[:favorite_course])
  end

  def destroy
    delete_course(:favorite_courses, params[:favorite_course])
  end

  def export
    if current_user.student? && !@state[:queued] && !params[:csys_password].blank?
      BookmarkingCoursesJob.perform_later(current_user, params[:csys_password])
    else
      if current_user.student?
        redis_state(message: '工作尚未結束或密碼空白')
      else
        redis_state(message: '非學生帳號，請洽管理員')
      end
    end
  end

  private

  def redis_state(**args)
    @state = JSON.parse($job_redis.get(current_user.id) || '{}')<commit_msg>Fix undefined method error when visit /user/favorite_courses<commit_after>class Users::FavoriteCoursesController < ApplicationController
  include CourseManager

  before_action :authenticate_user!
  before_action :redis_state, only: [:show, :export]

  def show
    @courses = Course.by_code(current_user.favorite_courses).includes(:entries, comments: :replies)
  end

  def create
    append_course(:favorite_courses, params[:favorite_course])
  end

  def destroy
    delete_course(:favorite_courses, params[:favorite_course])
  end

  def export
    if current_user.student? && !@state[:queued] && !params[:csys_password].blank?
      BookmarkingCoursesJob.perform_later(current_user, params[:csys_password])
    else
      if current_user.student?
        redis_state(message: '工作尚未結束或密碼空白')
      else
        redis_state(message: '非學生帳號，請洽管理員')
      end
    end
  end

  private

  def redis_state(**args)
    @state = JSON.parse($job_redis.get(current_user.id) || '{}')
{'fraction_non_alphanumeric': 0.10504420176807072, 'fraction_numerical': 0.0, 'mean_word_length': 4.512893982808023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4734966', 'n_tokens_mistral': 664, 'n_tokens_neox': 663, 'n_words': 112}