Class: Api::V5::SearchesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v5/searches_controller.rb

Overview

typed: ignore frozen_string_literal: true

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema

Instance Method Summary collapse

Methods inherited from BaseController

#identity_cache_memoization

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#suggestObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/api/v5/searches_controller.rb', line 5

def suggest
  suggests = fetch_suggestions
  cache_key = "#{self.class}:suggest:#{CityHash.hash32([I18n.locale, suggests.cache_key])}"
  my_response_cache cache_key, :json, public: true do
    grouped_suggests = suggests.order(rank: :asc).group_by(&:suggestion_type)
    promotions = grouped_suggests['promotion'] || []
    interestings = grouped_suggests['interesting'] || []
    restaurants = suggests.order(rank: :asc).group_by(&:suggestion_type)['outlet'] || []

    promotions_data = build_promotions_data(promotions)
    interestings_data = build_interestings_data(interestings)
    restaurants_data = build_restaurants_data(restaurants)

    {
      data: {
        promotions: promotions_data,
        interestings: interestings_data,
        restaurants: restaurants_data,
      },
      success: true,
      message: nil,
    }
  end
  set_status_header(true)
end