Class: Api::V5::BannersController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::BannersController
- Includes:
- ImageHelper
- Defined in:
- app/controllers/api/v5/banners_controller.rb
Overview
used in promotion page on website
Constant Summary
Constants inherited from BaseController
Api::V5::BaseController::CACHE_NAMESPACE, Api::V5::BaseController::INTERNAL_SERVER_ERROR_MESSAGE, Api::V5::BaseController::ResponseSchema
Instance Method Summary collapse
-
#index ⇒ Object
Android has limitation, it can't send GET data with JSON body so we allow them to send String restaurant_tag_ids.
Methods included from ImageHelper
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#index ⇒ Object
Android has limitation, it can't send GET data with JSON body so we allow them to send String restaurant_tag_ids
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/api/v5/banners_controller.rb', line 10 def index page = params.fetch(:page, {}) city_id = params[:city_id] restaurant_tag_id = params[:restaurant_tag_id] cache_key = [CACHE_NAMESPACE, self.class, 'index', Banner.maximum(:updated_at), Time.zone.today, params[:restaurant_tag_ids], params[:restaurant_id], city_id, I18n.locale, page, restaurant_tag_id].join(':') return unless stale? cache_key, template: false my_response_cache cache_key, :json, public: true do = Banner.includes(:cities) if restaurant_tag_id.blank? = .includes(:translations).with_locale(I18n.locale) = .where(cities: { id: nil }).or(.where(cities: { id: city_id })) if city_id = .where(active: true) end = .page(page[:number]).per(page[:size]).order('order_number ASC') if params[:restaurant_id].present? restaurant = Restaurant.fetch params[:restaurant_id] = .where(restaurant_tag_id: restaurant.restaurant_tag_ids).includes(:restaurant_tag) elsif params[:restaurant_tag_ids].present? restaurant_tag_ids = if params[:restaurant_tag_ids].is_a?(String) params[:restaurant_tag_ids].split(',').compact else params[:restaurant_tag_ids] end = .where(restaurant_tag_id: Array.wrap(restaurant_tag_ids)).includes(:restaurant_tag) elsif restaurant_tag_id.present? = .where(restaurant_tag_id: restaurant_tag_id).includes(:restaurant_tag) else = .where(restaurant_tag_id: nil, restaurant_tag_group_id: nil) end .map do || .attributes.merge('mobile_versions' => fix_url(.mobile_versions), 'desktop_versions' => fix_url(.desktop_versions), 'mobile_retina_versions' => fix_url(.mobile_retina_versions), 'desktop_retina_versions' => fix_url(.desktop_retina_versions)) end end set_status_header(true) end |