<commit_before>class Api::V1::PiePiecesController < ApplicationController
  before_action :set_pie_piece, only: [:update, :destroy]

  def index
    @pie_pieces = PiePiece.all.user(get_current_user.id)
  end

  def create
    @pie_piece = PiePiece.new(pie_piece_params)

    if @pie_piece.save
      render json: @pie_piece, status: :created
    else
      render json: @pie_piece.errors, status: :unprocessable_entity
    end
  end

  def update
    if @pie_piece.update(pie_piece_params)
      render json: @pie_piece, status: :ok
    else
      render json: @pie_piece.errors, status: :unprocessable_entity
    end
  end

  def destroy
    @pie_piece.destroy
    head :no_content
  end

  private
    def set_pie_piece
      @pie_piece = PiePiece.joins(:pie).where(
        id: params[:id],
        pies: { user_id: get_current_user.id }
      ).take!
    end

    def pie_piece_params
      new_params = params.permit(
        :pie_id,
        :title
      )
    end
end<commit_msg>Require pie_id when creating a pie piece<commit_after>class Api::V1::PiePiecesController < ApplicationController
  before_action :set_pie_piece, only: [:update, :destroy]

  def index
    @pie_pieces = PiePiece.all.user(get_current_user.id)
  end

  def create
    @pie_piece = PiePiece.new(pie_piece_params.merge!(
      :pie_id => params.require(:pie_id)
    ))

    if @pie_piece.save
      render json: @pie_piece, status: :created
    else
      render json: @pie_piece.errors, status: :unprocessable_entity
    end
  end

  def update
    if @pie_piece.update(pie_piece_params)
      render json: @pie_piece, status: :ok
    else
      render json: @pie_piece.errors, status: :unprocessable_entity
    end
  end

  def destroy
    @pie_piece.destroy
    head :no_content
  end

  private
    def set_pie_piece
      @pie_piece = PiePiece.joins(:pie).where(
        id: params[:id],
        pies: { user_id: get_current_user.id }
      ).take!
    end

    def pie_piece_params
      new_params = params.permit(
        :title
      )
    end
end
{'fraction_non_alphanumeric': 0.0898379970544919, 'fraction_numerical': 0.0009818360333824251, 'mean_word_length': 2.830827067669173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '2551031', 'n_tokens_mistral': 714, 'n_tokens_neox': 693, 'n_words': 156}