Class: Api::V5::RestaurantTagGroupsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::RestaurantTagGroupsController
- Includes:
- Concerns::Authorization, Concerns::GetRestaurantList, Concerns::HhData::Restaurant
- Defined in:
- app/controllers/api/v5/restaurant_tag_groups_controller.rb
Overview
Restaurants
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
-
#index ⇒ Object
Data is refreshed each 30 minutes.
- #show ⇒ Object
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#index ⇒ Object
Data is refreshed each 30 minutes
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/api/v5/restaurant_tag_groups_controller.rb', line 11 def index page = params.fetch(:page, {}) filter = Api::V5::RestaurantTagGroupsFilter.new filter.init_default. page_number(page.fetch(:number, 1)). per_page(page.fetch(:size, 10)) set_status_header(true) my_response_cache "#{self.class}|index_expiration|:#{filter.collections.cache_key}|#{I18n.locale}", :json, public: true, public_expires_in: 1.hour do filter.as_json(serialization_context, minor_version_param, {}).merge(success: true, message: nil) end end |
#show ⇒ Object
24 25 26 27 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 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/api/v5/restaurant_tag_groups_controller.rb', line 24 def show if AdminSetting.enable_list_by_rank_feature.to_s == 'true' params[:tag_group_id] = params.require(:id) restaurant_list_by_rank(params) else restaurant_tag_group = RestaurantTagGroup.fetch(params.require(:id)) # todo to make it dynamic phase 2 group_landing_page = restaurant_tag_group.group_landing_pages.where(sort_type: 'manual').first restaurants = lambda do restaurant_tag_group.restaurants.active.not_expired end params[:sort_by] ||= :rank named_cache_key = "#{CACHE_NAMESPACE}:#{self.class}|#{restaurants.call.maximum(:updated_at)}|#{I18n.locale}" if params[:compact_mode].to_s == 'true' cache_key = CityHash.hash32([named_cache_key, 'compact', params, CompactRestaurant.maximum(:updated_at), GroupLandingPage.maximum(:updated_at), I18n.locale]) page = params.fetch(:page, {}) my_response_cache cache_key, :json, public: true do restaurants = restaurants.call restaurant_ids = restaurants.map(&:id) branch_ids = restaurants.map(&:branch_id) filter = CompactRestaurantsFilter.new filter.filter_restaurant_and_branch_ids(restaurant_ids: restaurant_ids, branch_ids: branch_ids) filter.filter_by_city_id(params[:city_id]) if params[:city_id].present? filter.set_group_landing_page(group_landing_page&.id) if group_landing_page.present? filter.sort_by(params[:sort_by]) filter.page_number(page.fetch(:number, 1)).per_page(page.fetch(:size, 10)) filter.as_json(serialization_context, minor_version_param, { include: 'group_landing_page' }).merge( success: true, message: nil, ) end else restaurant_list(named_cache_key, restaurants) end end end |