<commit_before>module Rez
  class ItemsController < ApplicationController

    before_action :toke, only: [:create, :update, :destroy]
    before_action :set_item, only: [:show, :update, :destroy]
    before_action :set_resume, only: [:index]

    def create
      @item = Item.new(item_params)
      if @item.save
        render json: @item, status: :created
      else
        render json: @item.errors, status: :bad_request
      end
    end

    def index
      if @resume
        render json: @resume.items.includes([:paragraphs, :bullets])
      else
        render json: Item.includes([:paragraphs, :bullets])
      end
    end

    def show
      render json: @item
    end

    def update
      @item.update(item_params)
      render json: @item
    end

    def destroy
      @item.destroy
      head :no_content
    end

    private

    def set_item
      @item = Item.find_by(id: params[:id])
      head :not_found unless @item
    end

    def set_resume
      if params[:resume_id]
        @resume = Resume.find_by(id: params[:resume_id])
        head :not_found unless @resume
      end
    end

    def item_params
      params.require(:item).permit(:name, :title, :heading, :visible)
    end
  end
end<commit_msg>refactor ItemsController index<commit_after>module Rez
  class ItemsController < ApplicationController

    before_action :toke, only: [:create, :update, :destroy]
    before_action :set_resume, only: [:index]
    before_action :set_item, only: [:show, :update, :destroy]
    before_action :set_items, only: [:index]

    def create
      @item = Item.new(item_params)
      if @item.save
        render json: @item, status: :created
      else
        render json: @item.errors, status: :bad_request
      end
    end

    def index
      render json: @items.includes([:paragraphs, :bullets])
    end

    def show
      render json: @item
    end

    def update
      @item.update(item_params)
      render json: @item
    end

    def destroy
      @item.destroy
      head :no_content
    end

    private

    def set_resume
      if params[:resume_id]
        @resume = Resume.find_by(id: params[:resume_id])
        head :not_found unless @resume
      end
    end

    def set_item
      @item = Item.find_by(id: params[:id])
      head :not_found unless @item
    end

    def set_items
      if @resume
        @items = @resume.items
      else
        @items = Item.all
      end
    end

    def item_params
      params.require(:item).permit(:name, :title, :heading, :visible)
    end
  end
end
{'fraction_non_alphanumeric': 0.09491925955100433, 'fraction_numerical': 0.0, 'mean_word_length': 2.3289646133682833, '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': '3615903', 'n_tokens_mistral': 810, 'n_tokens_neox': 801, 'n_words': 222}