<commit_before>class Library::Music::YearInReviewReleasesController < ApplicationController
  include ::MusicMetadataEnrichment::BaseController
  include Applicat::Mvc::Controller::Resource

  authorize_resource class: 'YearInReviewMusicRelease', except: [:move]
  
  def index
    @user = User.find(params[:user_id])
    find_year_in_review
    
    if request.xhr?
      get_year_in_review_releases
      render partial: 'library/music/year_in_review_releases/collection'
    end
  end
  
  def new
    build_resource
    render layout: false
  end
  
  def create
    build_resource
    
    if @year_in_review_release.save
      @notice = I18n.t('year_in_review_music_releases.create.successful') 
      get_year_in_review_releases
    end
    
    render layout: false
  end
  
  def move
    @year_in_review_release = YearInReviewMusicRelease.find(params[:id])
    
    authorize! :move, @year_in_review_release
    
    @year_in_review_release.insert_at(params[:position].to_i)
    
    render nothing: true
  end
  
  private
  
  def find_year_in_review
    @year_in_review = @user.years_in_review_music.where(year: params[:year]).first
  end
  
  def build_resource
    @user = current_user
    find_year_in_review
    params[:year_in_review_music_release] ||= {}
    @year_in_review_release = @year_in_review.releases.new(release_id: params[:year_in_review_music_release][:release_id])
  end
  
  def get_year_in_review_releases
    @year_in_review_releases = @year_in_review.releases.order('position ASC')
  end
end<commit_msg>refs #22 add artist of release to library artists if not already done through adding a release to a year in review.<commit_after>class Library::Music::YearInReviewReleasesController < ApplicationController
  include ::MusicMetadataEnrichment::BaseController
  include Applicat::Mvc::Controller::Resource

  authorize_resource class: 'YearInReviewMusicRelease', except: [:move]
  
  def index
    @user = User.find(params[:user_id])
    find_year_in_review
    
    if request.xhr?
      get_year_in_review_releases
      render partial: 'library/music/year_in_review_releases/collection'
    end
  end
  
  def new
    build_resource
    render layout: false
  end
  
  def create
    build_resource
    
    if @year_in_review_release.save
      MusicLibraryArtist.create(user_id: current_user.id, artist_id: @year_in_review_release.artist_id)
      @notice = I18n.t('year_in_review_music_releases.create.successful') 
      get_year_in_review_releases
    end
    
    render layout: false
  end
  
  def move
    @year_in_review_release = YearInReviewMusicRelease.find(params[:id])
    
    authorize! :move, @year_in_review_release
    
    @year_in_review_release.insert_at(params[:position].to_i)
    
    render nothing: true
  end
  
  private
  
  def find_year_in_review
    @year_in_review = @user.years_in_review_music.where(year: params[:year]).first
  end
  
  def build_resource
    @user = current_user
    find_year_in_review
    params[:year_in_review_music_release] ||= {}
    @year_in_review_release = @year_in_review.releases.new(release_id: params[:year_in_review_music_release][:release_id])
  end
  
  def get_year_in_review_releases
    @year_in_review_releases = @year_in_review.releases.order('position ASC')
  end
end
{'fraction_non_alphanumeric': 0.07704019488428746, 'fraction_numerical': 0.0018270401948842874, 'mean_word_length': 4.085139318885449, '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': '1918632', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1069, 'n_words': 186}