Class: Api::Vendor::V1::LocationsController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::PaginationParam
Defined in:
app/controllers/api/vendor/v1/locations_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE

Instance Attribute Summary

Attributes inherited from BaseController

#vendor

Instance Method Summary collapse

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
# File 'app/controllers/api/vendor/v1/locations_controller.rb', line 5

def index
  filter = Api::Vendor::V1::LocationsFilter.new.
    init_default

  city_id = params[:city_id]
  filter.by_city_id(city_id) if city_id.present?

  filter.page_number(page_number_param).per_page(page_size_param)

  cache_key = "#{CACHE_NAMESPACE}:#{self.class}:#{I18n.locale}:#{filter.collections.cache_key}:#{params[:sort]}#{city_id}"

  my_response_cache(cache_key, :json, public: true) do
    options = {}
    filter.sort_by(params[:sort])
    cuisines = filter.collections
    serialized_data = Api::Vendor::V1::LocationSerializer.new(cuisines, options).serializable_hash
    serialized_data[:success] = true
    serialized_data[:message] = nil
    serialized_data
  end
end