<commit_before>class RecipeController < ApplicationController
  #          -----User Recipe Homepage-----
  get '/recipes' do
    redirect_if_not_logged_in

    @user = current_user
    erb :'/recipes/recipes'
  end

  #          -----Create Recipe-----
  get '/recipes/new' do
    redirect_if_not_logged_in

    erb :'/recipes/create_recipe'
  end

  post '/recipes' do
    redirect_if_not_logged_in

    @recipe = current_user.recipes.build(params)
    if @recipe.save
      flash[:new] = "Successully saved!"
      redirect "/recipes"
    else
      flash[:new] = "There was a problem saving your recipe. Please try again."
      session[:params] = params
      redirect "/recipes/new"
    end
  end

  #          -----Show Recipe-----
  get '/recipes/:id' do
    redirect_if_not_logged_in

    @recipe = Recipe.find(params[:id])
    erb :'/recipes/show_recipe'
  end

  #          -----Edit Recipe-----
  get '/recipes/:id/edit' do
    redirect_if_not_logged_in


    @user = current_user
    @recipe = Recipe.find(params[:id])
    if @user && @user.id == @recipe.user.id
      erb :'/recipes/edit_recipe'
    else
      flash[:not_owner] = "You do not own this."
      redirect "/recipes/#{params[:id]}"
    end
  end

  patch '/recipes/:id' do
    redirect_if_not_logged_in

    @user = current_user
    @recipe = Recipe.find(params[:id])
    if @user.id == @recipe.user.id
      @recipe = Recipe.find(params[:id])
      if @recipe.update(params[:recipe])
        flash[:edit] = "Successfully saved!"
        redirect "/recipes/#{params[:id]}"
      else
        session[:params] = params
        flash[:edit] = "There was a problem saving your changes. Please try again."
        redirect "/recipes/#{params[:id]}/edit"
      end
    else
      flash[:owner] = "You do not own this."
      redirect "/recipes/#{params[:id]}"
    end
  end

  #          -----Delete-----
  delete '/recipes/:id/delete' do
    redirect_if_not_logged_in

    @recipe = Recipe.find(params[:id])
    if owned?
      @recipe.destroy
      flash[:delete] = "Recipe deleted."
      redirect "/recipes"
    else
      flash[:owner] = "You do not own this."
      redirect "/recipes/#{@recipe.id}"
    end
  end



end
<commit_msg>added functionality to the recipe controller to share and save the recipe to your own account, so it can be edited/deleted<commit_after>class RecipeController < ApplicationController
  #          -----User Recipe Homepage-----
  get '/recipes' do
    redirect_if_not_logged_in

    @user = current_user
    erb :'/recipes/recipes'
  end

  #          -----Create Recipe-----
  get '/recipes/new' do
    redirect_if_not_logged_in

    erb :'/recipes/create_recipe'
  end

  post '/recipes' do
    redirect_if_not_logged_in

    @recipe = current_user.recipes.build(params)
    if @recipe.save
      flash[:new] = "Successully saved!"
      redirect "/recipes"
    else
      flash[:new] = "There was a problem saving your recipe. Please try again."
      session[:params] = params
      redirect "/recipes/new"
    end
  end

  #          -----Show Recipe-----
  get '/recipes/:id' do
    redirect_if_not_logged_in

    @recipe = Recipe.find(params[:id])
    erb :'/recipes/show_recipe'
  end

  #          -----Share Recipe-----
  get '/recipes/:id/share' do
    redirect_if_not_logged_in

    @user = current_user
    @recipe = Recipe.find(params[:id])
    erb :'/recipes/share_recipe'
  end

  #          -----Save Recipe-----
  patch '/recipes/:id/save' do
    redirect_if_not_logged_in

    @user = current_user
    @recipe = Recipe.find(params[:id]).dup
    hash = @recipe.attributes.to_options
    @new_recipe = @user.recipes.create(hash)

    redirect "/recipes/#{@new_recipe.id}"
  end

  #          -----Edit Recipe-----
  get '/recipes/:id/edit' do
    redirect_if_not_logged_in

    @user = current_user
    @recipe = Recipe.find(params[:id])
    if @user && owned?
      erb :'/recipes/edit_recipe'
    else
      flash[:not_owner] = "You do not own this."
      redirect "/recipes/#{params[:id]}"
    end
  end

  patch '/recipes/:id' do
    redirect_if_not_logged_in

    @user = current_user
    @recipe = Recipe.find(params[:id])
    if @user.id == @recipe.user.id
      @recipe = Recipe.find(params[:id])
      if @recipe.update(params[:recipe])
        flash[:edit] = "Successfully saved!"
        redirect "/recipes/#{params[:id]}"
      else
        session[:params] = params
        flash[:edit] = "There was a problem saving your changes. Please try again."
        redirect "/recipes/#{params[:id]}/edit"
      end
    else
      flash[:owner] = "You do not own this."
      redirect "/recipes/#{params[:id]}"
    end
  end

  #          -----Delete-----
  delete '/recipes/:id/delete' do
    redirect_if_not_logged_in

    @recipe = Recipe.find(params[:id])
    if owned?
      @recipe.destroy
      flash[:delete] = "Recipe deleted."
      redirect "/recipes"
    else
      flash[:owner] = "You do not own this."
      redirect "/recipes/#{@recipe.id}"
    end
  end

end

{'fraction_non_alphanumeric': 0.14214414054701538, 'fraction_numerical': 0.0, 'mean_word_length': 2.276651406147809, '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': '4106283', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1670, 'n_words': 385}