Module: Api::V5::Concerns::HhData::Restaurant
- Includes:
- ResponseCacheConcern
- Included in:
- RestaurantTagGroupsController
- Defined in:
- app/controllers/api/v5/concerns/hh_data/restaurant.rb
Overview
module to handle HhData Api
Constant Summary collapse
- CACHE_NAMESPACE =
'api_v5_cache'.freeze
Instance Method Summary collapse
Methods included from ResponseCacheConcern
Instance Method Details
#restaurant_list_by_rank(params) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/api/v5/concerns/hh_data/restaurant.rb', line 8 def restaurant_list_by_rank(params) compact_mode = params[:compact_mode].to_s == 'true' is_compact = compact_mode ? 1 : 0 top_n = params.fetch(:top_n, 0) tag_group_id = params.fetch(:tag_group_id, 0) res_cache_key = if compact_mode CompactRestaurant.maximum(:updated_at) else Restaurant.active.not_expired.cache_key end cache_key = CityHash.hash32([params, I18n.locale, CACHE_NAMESPACE, res_cache_key]) my_response_cache cache_key, :json do api_data = HhApiData::Restaurant.new(id: tag_group_id, params: { is_compact: is_compact, top_n: top_n }) api_data.pagination(params.fetch(:page, {})) = {} [:each_serializer] = if compact_mode Api::V5::FeaturedRestaurantSerializer else Api::V5::RestaurantSerializer end .merge! serialization_context: serialization_context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, minor_version: minor_version_param ActiveModelSerializers::SerializableResource.new(api_data.collections_by_rank, ).as_json end end |