Class: Api::Aoa::V1::CuisinesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/aoa/v1/cuisines_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE

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



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/api/aoa/v1/cuisines_controller.rb', line 3

def index
  page = params.fetch(:page, {})

  filter = Api::Aoa::CuisinesFilter.new.init_default

  city_id = params[:city_id].to_i.positive? ? params[:city_id] : City.find_bangkok.id
  filter.by_city_id(city_id) if city_id.present?
  filter.page_number(page[:number]).per_page(page[:size])
  filter.sort_by(params[:sort])

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

  my_response_cache cache_key, :json, public: true do
    Api::Aoa::V1::CuisineSerializer.new(filter.collections).as_json
  end
end