<commit_before>class BathroomsController < ApplicationController

  before_filter :encode_search, only: :index
  before_filter :list_bathrooms, only: [:index, :list]
  before_filter :find_bathroom, only: [:show, :update, :destroy, :up_vote, :down_vote]

  def index
  end

	def list
		render json: @bathrooms
	end

  def show
  end

  def new
    @bathroom = Bathroom.new
  end

  def create
    @bathroom = Bathroom.new(permitted_params)

    if @bathroom.save
      flash[:notice] = "A new bathroom entry has been created for #{@bathroom.name}."
      redirect_to @bathroom
    else
      flash[:alert] = "There was a problem saving your entry to the database."
      render 'new'
    end
  end

  def update
    if @bathroom.update(permitted_params)
      flash[:notice] = "This bathroom entry has been updated."
      redirect_to @bathroom
    else
      flash[:alert] = "There was an unexpected problem updating this post."
      render 'edit'
    end
  end

  def edit
  end

  def destroy
    if @bathroom.destroy
      flash[:notice] = "This bathroom entry has been deleted."
      redirect_to bathrooms_path
    else
      flash[:alert] = "This bathroom entry could not be deleted."
      redirect_to @bathroom
    end
  end

  def down_vote
    @bathroom.downvote += 1
    if @bathroom.save
      flash[:notice] = "This bathroom has been downvoted! Thank you for contributing to our community. "
      redirect_to @bathroom
    else
      flash[:alert] = "There was an unexpected problem downvoting this post."
      redirect_to @bathroom
    end
  end

  def up_vote
    @bathroom.upvote += 1
    if @bathroom.save
      flash[:notice] = "This bathroom has been upvoted! Thank you for contributing to our community. "
      redirect_to @bathroom
    else
      flash[:alert] = "There was an unexpected problem upvoting this post."
      redirect_to @bathroom
    end
  end


  private

  def list_bathrooms
    @bathrooms = Bathroom.ada(params[:adafilter]).unisex(params[:unisexfilter])

    @bathrooms = if params[:search].present? || params[:map] == "1"
      @bathrooms.near([params[:lat], params[:long]], 20, :order => 'distance')
    else
      @bathrooms.reverse_order
    end

    @bathrooms = @bathrooms.limit(20)
  end

  def find_bathroom
    @bathroom = Bathroom.find(params[:id])
  end

  def permitted_params
    params.require(:bathroom).permit!
  end

  SAN_FRANCISCO_LOCATION = [37.7577, -122.4376]

  def encode_search
    error = nil

    if (!params[:search].blank? || params[:map] == "1") && (!params[:lat] || !params[:long])
      location = Geocoder.coordinates(params[:search]) if params[:search]
      error = "There was an error searching for your location." unless location
      location ||= SAN_FRANCISCO_LOCATION
<commit_msg>deleting server side geocoding - geocoding is done client side now.<commit_after>class BathroomsController < ApplicationController

  before_filter :encode_search, only: :index
  before_filter :list_bathrooms, only: [:index, :list]
  before_filter :find_bathroom, only: [:show, :update, :destroy, :up_vote, :down_vote]

  def index
  end

	def list
		render json: @bathrooms
	end

  def show
  end

  def new
    @bathroom = Bathroom.new
  end

  def create
    @bathroom = Bathroom.new(permitted_params)

    if @bathroom.save
      flash[:notice] = "A new bathroom entry has been created for #{@bathroom.name}."
      redirect_to @bathroom
    else
      flash[:alert] = "There was a problem saving your entry to the database."
      render 'new'
    end
  end

  def update
    if @bathroom.update(permitted_params)
      flash[:notice] = "This bathroom entry has been updated."
      redirect_to @bathroom
    else
      flash[:alert] = "There was an unexpected problem updating this post."
      render 'edit'
    end
  end

  def edit
  end

  def destroy
    if @bathroom.destroy
      flash[:notice] = "This bathroom entry has been deleted."
      redirect_to bathrooms_path
    else
      flash[:alert] = "This bathroom entry could not be deleted."
      redirect_to @bathroom
    end
  end

  def down_vote
    @bathroom.downvote += 1
    if @bathroom.save
      flash[:notice] = "This bathroom has been downvoted! Thank you for contributing to our community. "
      redirect_to @bathroom
    else
      flash[:alert] = "There was an unexpected problem downvoting this post."
      redirect_to @bathroom
    end
  end

  def up_vote
    @bathroom.upvote += 1
    if @bathroom.save
      flash[:notice] = "This bathroom has been upvoted! Thank you for contributing to our community. "
      redirect_to @bathroom
    else
      flash[:alert] = "There was an unexpected problem upvoting this post."
      redirect_to @bathroom
    end
  end


  private

  def list_bathrooms
    @bathrooms = Bathroom.ada(params[:adafilter]).unisex(params[:unisexfilter])

    @bathrooms = if params[:search].present? || params[:map] == "1"
      @bathrooms.near([params[:lat], params[:long]], 20, :order => 'distance')
    else
      @bathrooms.reverse_order
    end

    @bathrooms = @bathrooms.limit(20)
  end

  def find_bathroom
    @bathroom = Bathroom.find(params[:id])
  end

  def permitted_params
    params.require(:bathroom).permit!
  end

  SAN_FRANCISCO_LOCATION = [37.7577, -122.4376]

  def encode_search
    error = nil

    if (!params[:search].blank? || params[:map] == "1") && (!params[:lat] || !params[:long])
      location = params[:search] if params[:search]
      error = "There was an error searching for your location." unless location
      location ||= SAN_FRANCISCO_LOCATION

{'fraction_non_alphanumeric': 0.09906508450197771, 'fraction_numerical': 0.007551240560949299, 'mean_word_length': 3.0964653902798234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2635008', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1739, 'n_words': 523}