<commit_before>class MoviesController < ApplicationController
  before_action :require_authentication

  def show
    @movie = Movie.get_by_id(params[:id])
  end

  def search
    @movies = Movie.search_by_string(params[:search][:search_string])
    render :search
  end

  def watched
    @movie = current_or_new_movie(params[:format])
    @status = current_or_new_status(@movie)

    @status.update_attribute(:watched, true)

    redirect_to movie_path(@movie.api_id)
  end

  def unwatched
    @movie = current_or_new_movie(params[:format])
    @status = current_or_new_status(@movie)

    @status.update_attribute(:watched, false)

    redirect_to movie_path(@movie.api_id)
  end

  private
  def current_or_new_movie(id)
    @movie = Movie.find_by_api_id(id)

    if @movie.nil?
      @api_movie = Movie.get_by_id(id)
      @movie = Movie.new
      @movie.api_id = id
      @movie.title = @api_movie["title"]
      @movie.thumbnail = @api_movie["thumbnail"]
      @movie.save!
    end

    @movie
  end

  def current_or_new_status(movie)
    @status = current_user.statuses.find_by_movie_id(movie)

    if @status.nil?
      @status = Status.new
      @status.user = current_user
      @status.movie = movie
      @status.save!<commit_msg>missed the flashes<commit_after>class MoviesController < ApplicationController
  before_action :require_authentication

  def show
    @movie = Movie.get_by_id(params[:id])
  end

  def search
    @movies = Movie.search_by_string(params[:search][:search_string])
    render :search
  end

  def watched
    @movie = current_or_new_movie(params[:format])
    @status = current_or_new_status(@movie)

    @status.update_attribute(:watched, true)

    flash[:success] = "You have successfully watched a movie!"
    redirect_to movie_path(@movie.api_id)
  end

  def unwatched
    @movie = current_or_new_movie(params[:format])
    @status = current_or_new_status(@movie)

    @status.update_attribute(:watched, false)

    flash[:success] = "You want to watch a movie!"
    redirect_to movie_path(@movie.api_id)
  end

  private
  def current_or_new_movie(id)
    @movie = Movie.find_by_api_id(id)

    if @movie.nil?
      @api_movie = Movie.get_by_id(id)
      @movie = Movie.new
      @movie.api_id = id
      @movie.title = @api_movie["title"]
      @movie.thumbnail = @api_movie["thumbnail"]
      @movie.save!
    end

    @movie
  end

  def current_or_new_status(movie)
    @status = current_user.statuses.find_by_movie_id(movie)

    if @status.nil?
      @status = Status.new
      @status.user = current_user
      @status.movie = movie
      @status.save!
{'fraction_non_alphanumeric': 0.10732081257186661, 'fraction_numerical': 0.0, 'mean_word_length': 3.4922547332185885, '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': '5508296', 'n_tokens_mistral': 951, 'n_tokens_neox': 873, 'n_words': 161}