<commit_before>class VotesController < ApplicationController

  def upvote
    @story = Story.find(params[:id])
    @vote = Vote.new(user_id: 1, story_id: @story.id, liked: true)
    unless @vote.save
      db_vote = Vote.where(user_id: 1, votable_id: @story.id)[0]
      db_vote.update(liked: true)
    end
    redirect_to :back
  end

  def downvote
    @story = Story.find(params[:id])
    @vote = Vote.new(user_id: 1, story_id: @story.id, liked: false)
    unless @vote.save
      db_vote = Vote.where(user_id: current_user.id, votable_id: @story.id)[0]
      db_vote.update(liked: false)
    end
    redirect_to :back
  end

  private

  def vote_params
    params.require(:vote).permit(:liked, :story_id, :user_id)
  end
end
<commit_msg>fix votes to only allow 1 vote, hardcoded current user for testing<commit_after>class VotesController < ApplicationController

  def upvote
    @current_user = User.find(1) # for testing purposes - will delete this later
    @story = Story.find(params[:id])
    @vote = Vote.where(user_id: @current_user.id, story_id: @story.id)
    if @vote.count == 0
      @vote.create(user_id: @current_user.id, story_id: @story.id, liked:true)
    else
      redirect_to :back
    end
  end

  def downvote
    @current_user = User.find(1) # for testing purposes - will delete this later
    @story = Story.find(params[:id])
    @vote = Vote.where(user_id: @current_user.id, story_id: @story.id)
    if @vote.count == 0
      @vote.create(user_id: @current_user.id, story_id: @story.id, liked: false)
    else
      redirect_to :back
    end
  end

  private

  def vote_params
    params.require(:vote).permit(:liked, :story_id, :user_id)
  end
end

{'fraction_non_alphanumeric': 0.1189767995240928, 'fraction_numerical': 0.00594883997620464, 'mean_word_length': 3.3802083333333335, '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': '3933948', 'n_tokens_mistral': 609, 'n_tokens_neox': 585, 'n_words': 144}