Class: Api::V5::CuisinesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v5/cuisines_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

#indexObject



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

def index
  page = params.fetch(:page, {})
  filter = Api::V5::CuisinesFilter.new.init_default

  city_id = params[:city_id]
  ids = params[:cuisine_ids]

  filter.by_ids(ids) if ids.present?
  filter.by_city_id(city_id) if city_id.present?

  sort_by = params.fetch(:sort, 'total_restaurants_desc')

  cache_key = "#{CACHE_NAMESPACE}:#{self.class}:#{I18n.locale}:#{RestaurantTag.cuisines_cache_key}:index#{sort_by}#{city_id}#{ids}"

  my_response_cache(cache_key, :json, public: true) do
    filter.sort_by(sort_by)
    filter.page_number(page[:number]).per_page(page[:size])
    options = {}
    filter.as_json(serialization_context, minor_version_param, options).merge(success: true, message: nil)
  end

  set_status_header(true)
end