mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-29 10:18:29 -04:00
- Updated MemberLocationsController to use a hash for location updates, ensuring coordinates are not geocoded again. - Changed response status codes in member_locations_spec to use symbols for better readability. - Modified PlacesController to use parentheses for defining MEMBER_FIELDS. - Enhanced SuggestionsController to disable Rails/SkipsModelValidations for update_columns. - Updated SeasonsHelper to use compact_blank for cleaner output. - Refactored MemberDashboard service for improved readability and performance. - Adjusted migration files to use parentheses for index definitions. - Updated schema.rb to maintain consistency in index definitions. - Added SampleData class to generate sample data for development. - Cleaned up sample_data.rake task to utilize the new SampleData class. - Updated tests in member_dashboard_spec and place_suggester_spec for consistency and readability.
60 lines
1.7 KiB
Ruby
60 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PlacesController < ApplicationController
|
|
skip_authorize_resource
|
|
before_action :authenticate_member!, only: :suggest
|
|
respond_to :html, :json
|
|
|
|
MEMBER_FIELDS = %i(id login_name slug location latitude longitude).freeze
|
|
|
|
def index
|
|
respond_to do |format|
|
|
format.html
|
|
# json response is whatever we want to map here
|
|
format.json do
|
|
members = Member.located.paginate(page: params[:page]).pluck(*MEMBER_FIELDS).map do |row|
|
|
MEMBER_FIELDS.zip(row).to_h
|
|
end
|
|
render json: members
|
|
end
|
|
end
|
|
end
|
|
|
|
# GET /places/london
|
|
# GET /places/london.json
|
|
def show
|
|
@place = params[:place] # used for page title
|
|
@nearby_members = Member.nearest_to(params[:place])
|
|
respond_to do |format|
|
|
format.html # show.html.haml
|
|
format.json do
|
|
render json: @nearby_members.as_json(only: MEMBER_FIELDS)
|
|
end
|
|
end
|
|
end
|
|
|
|
# GET /places/suggest.json?q=wellington
|
|
# GET /places/suggest.json?lat=-41.3&lng=174.8
|
|
# Named places to choose from, for the dialog that asks where someone gardens.
|
|
def suggest
|
|
places = if params[:q].present?
|
|
PlaceSuggester.search(params[:q])
|
|
elsif params[:lat].present? && params[:lng].present?
|
|
PlaceSuggester.reverse(Float(params[:lat]), Float(params[:lng]))
|
|
else
|
|
[]
|
|
end
|
|
render json: places
|
|
rescue ArgumentError
|
|
render json: [], status: :unprocessable_content
|
|
end
|
|
|
|
def search
|
|
if params[:new_place].empty?
|
|
redirect_to places_path, alert: t('messages.invalid_location')
|
|
else
|
|
redirect_to place_path(params[:new_place])
|
|
end
|
|
end
|
|
end
|