Class: Api::V5::CitiesController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::CitiesController
- Defined in:
- app/controllers/api/v5/cities_controller.rb
Overview
Cities
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/api/v5/cities_controller.rb', line 8 def index cache_key = "#{CACHE_NAMESPACE}:#{self.class}:index:#{City.maximum(:updated_at)}:#{MyLocaleManager.normalize_locale}" my_response_cache cache_key, :json, public: true do today = Date.current_date cities = City.joins(:restaurants). includes(:country). where(restaurants: { active: true }). where('date(restaurants.expiry_date) >= ?', today). group('cities.id'). order('cities.display_order ASC'). having('count(restaurants.id) >= 10') ActiveModelSerializers::SerializableResource.new( cities, { each_serializer: Api::V5::CitySerializer, adapter: :json_api }, ).serializable_hash.merge(success: true, message: nil).as_json end end |
#restaurant_tags ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/api/v5/cities_controller.rb', line 28 def city_id = params[:city_id] city = City.find_by(id: city_id) if city_id.present? if city.nil? render json: { success: true, message: nil, data: nil } else cache_key = "#{CACHE_NAMESPACE}:#{self.class}:city_id:#{city_id}:restaurant_tags:#{MyLocaleManager.normalize_locale}" my_response_cache cache_key, :json do = (city_id) if city_id.present? data = .as_json(except: [:id, :city_id]).first || {} { success: true, message: nil, data: { popular_zone: data['popular_zone'] || 0, shopping_mall: data['shopping_mall'] || 0, bts_route: data['bts_route'] || 0, mrt_route: data['mrt_route'] || 0, facility: data['facility'] || 0, }, } end set_status_header(true) end end |