Class: Api::V5::HomesController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::HomesController
- Includes:
- Concerns::Authorization, Concerns::PaginationParam, ImageHelper
- Defined in:
- app/controllers/api/v5/homes_controller.rb
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
- #deals ⇒ Object
- #flash_sales ⇒ Object
-
#section_1 ⇒ Object
2nd, CompactRestaurant.
-
#section_10 ⇒ Object
13th section.
-
#section_11 ⇒ Object
10th CompactRestaurant.
-
#section_12 ⇒ Object
12th NOT USED by app.
-
#section_13 ⇒ Object
11th (Restaurant card, not compact), special section, don't change this!.
-
#section_14 ⇒ Object
3rd, special section, don't change this! restaurant card, not compact.
-
#section_3 ⇒ Object
1st, CompactRestaurant.
-
#section_4 ⇒ Object
top categories location 5th, Restaurant Tag.
-
#section_5 ⇒ Object
4rd popular brand, Branch.
-
#section_6 ⇒ Object
8th, CompactRestaurant.
-
#section_7 ⇒ Object
top categories cuisine 5th, Restaurant Tag.
-
#section_8 ⇒ Object
7th, CompactRestaurant.
-
#section_9 ⇒ Object
9th, CompactRestaurant.
- #section_banner ⇒ Object
-
#sections ⇒ Object
Provide all section info.
- #settings ⇒ Object
- #tags ⇒ Object
Methods included from ImageHelper
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#deals ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/api/v5/homes_controller.rb', line 126 def deals city_id_param = params[:city_id].to_i.positive? ? params[:city_id] : nil filter = Api::V5::SearchIconsFilter.new filter.by_city_id(city_id_param) filter.build_collections set_status_header(true) cache_key = "#{CACHE_NAMESPACE}:#{self.class}:#{I18n.locale}:#{filter.collections.cache_key}:index:#{params}" my_response_cache cache_key, :json, public: true do filter.as_json(serialization_context, minor_version_param, {}). merge(success: true, message: nil) end end |
#flash_sales ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/api/v5/homes_controller.rb', line 104 def flash_sales cron = '59 8 * * *' next_reset_at = Fugit::Cron.parse("#{cron} #{Time::THAILAND_ZONE}").next_time.to_utc_time cache_key = "#{self.class}:index:flash_sales:#{FlashSale.maximum(:updated_at)}:#{next_reset_at}:#{I18n.locale}" my_response_cache(cache_key, :json) do flash_sale_ids = FlashSale.flash_sale_outlet_ids collection = if flash_sale_ids.blank? Restaurant.none else Restaurant.where(id: flash_sale_ids).order("FIELD(id, #{flash_sale_ids.join(', ')})") end filter = Api::V5::RestaurantsFilter.new(collection) filter.as_json(serialization_context, minor_version_param, { compact_mode: false }). merge(success: true, message: nil). merge(next_reset_at: next_reset_at) end end |
#section_1 ⇒ Object
2nd, CompactRestaurant
41 42 43 |
# File 'app/controllers/api/v5/homes_controller.rb', line 41 def section_1 restaurant_section(__method__) end |
#section_10 ⇒ Object
13th section
100 101 102 |
# File 'app/controllers/api/v5/homes_controller.rb', line 100 def section_10 restaurant_section(__method__) end |
#section_11 ⇒ Object
10th CompactRestaurant
84 85 86 |
# File 'app/controllers/api/v5/homes_controller.rb', line 84 def section_11 restaurant_section(__method__) end |
#section_12 ⇒ Object
12th NOT USED by app
95 96 97 |
# File 'app/controllers/api/v5/homes_controller.rb', line 95 def section_12 restaurant_section(__method__) end |
#section_13 ⇒ Object
11th (Restaurant card, not compact), special section, don't change this!
89 90 91 92 |
# File 'app/controllers/api/v5/homes_controller.rb', line 89 def section_13 # restaurant_section(__method__) restaurant_section(__method__) end |
#section_14 ⇒ Object
3rd, special section, don't change this! restaurant card, not compact
47 48 49 |
# File 'app/controllers/api/v5/homes_controller.rb', line 47 def section_14 restaurant_section(__method__) end |
#section_3 ⇒ Object
1st, CompactRestaurant
36 37 38 |
# File 'app/controllers/api/v5/homes_controller.rb', line 36 def section_3 restaurant_section(__method__) end |
#section_4 ⇒ Object
top categories location 5th, Restaurant Tag
58 59 60 |
# File 'app/controllers/api/v5/homes_controller.rb', line 58 def section_4 restaurant_section(__method__) end |
#section_5 ⇒ Object
4rd popular brand, Branch
52 53 54 |
# File 'app/controllers/api/v5/homes_controller.rb', line 52 def section_5 restaurant_section(__method__) end |
#section_6 ⇒ Object
8th, CompactRestaurant
74 75 76 |
# File 'app/controllers/api/v5/homes_controller.rb', line 74 def section_6 restaurant_section(__method__) end |
#section_7 ⇒ Object
top categories cuisine 5th, Restaurant Tag
64 65 66 |
# File 'app/controllers/api/v5/homes_controller.rb', line 64 def section_7 restaurant_section(__method__) end |
#section_8 ⇒ Object
7th, CompactRestaurant
69 70 71 |
# File 'app/controllers/api/v5/homes_controller.rb', line 69 def section_8 restaurant_section(__method__) end |
#section_9 ⇒ Object
9th, CompactRestaurant
79 80 81 |
# File 'app/controllers/api/v5/homes_controller.rb', line 79 def section_9 restaurant_section(__method__) end |
#section_banner ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/controllers/api/v5/homes_controller.rb', line 159 def home_section = HomeSection.find_by(section_type: 'section_banner') if home_section.present? = home_section. = .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)) render json: { data: , success: true, message: nil, title: home_section.title, description: home_section.description, footer: home_section., tag_line: home_section.tag_line, slug: home_section.slug, icon: home_section.icon, clevertap_event_name: 'Hero Banner', punch_line: home_section.punch_line, section_template: home_section.section_template, section_image: nil, active: home_section.active?, } end end |
#sections ⇒ Object
Provide all section info
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'app/controllers/api/v5/homes_controller.rb', line 188 def sections cache_key = "#{self.class}:index:#{HomeSection.maximum(:updated_at)}:#{I18n.locale}" my_response_cache(cache_key, :json, public: true) do data = HomeSection.includes(:translations).reject do |section| HomeRestaurantSection::SECTION_ROUTE.invert[section.section_type.to_s.to_sym].nil? end = { serialization_context: serialization_context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, each_serializer: Api::V5::HomeRestaurantSectionSerializer, } result = render_to_string(json: ActiveModelSerializers::SerializableResource.new(data, ).as_json. merge(success: true, message: nil)) JSON.parse result end end |
#settings ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/api/v5/homes_controller.rb', line 11 def settings device_position = if params[:setting_for] == 'mobile' 'position_mobile' else 'position_web' end cache_key = "#{self.class}:index:#{HomeSection.maximum(:updated_at)}:#{params}:#{I18n.locale}" my_response_cache(cache_key, :json, public: true) do data = HomeSection.includes(:translations).order("CASE WHEN section_type = 'section_banner' THEN 0 ELSE 1 END, #{device_position} ASC") = { serialization_context: serialization_context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, city_id: params[:city_id], each_serializer: Api::V5::HomeSectionSerializer, } result = render_to_string(json: ActiveModelSerializers::SerializableResource.new(data, ).as_json. merge(success: true, message: nil)) JSON.parse result end end |
#tags ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/controllers/api/v5/homes_controller.rb', line 142 def home_section = HomeSection.find_by(slug: params[:slug]) return render json: { data: [], success: false, message: 'Not found' } if home_section.blank? cache_key = "#{self.class}:index:#{home_section.cache_key}:#{I18n.locale}" my_response_cache(cache_key, :json, public: true) do = {} = home_section. [:serialization_context] = serialization_context [:adapter] = :json_api [:each_serializer] = Api::V5::RestaurantTagSerializer ActiveModelSerializers::SerializableResource.new(, ).as_json.merge(success: true, message: nil) end end |