class Api::BenchesController < ApplicationController
  def create
    @bench = Bench.create(bench_params)

    if @bench.save
      render :show
    else
      render json: @bench.errors.full_messages
    end
  end

  def index
    @benches = params[:bounds] ? Bench.in_bounds(params[:bounds]) : Bench.all

    if params[:min_seating] && params[:max_seating]
      @benches = @benches.where(seating: (params[:min_seating]..params[:max_seating]))
    end

    render :index
  end

  private
  def bench_params
    params.require(:bench).permit(:description, :seating, :lat, :lng)
  end
end
