Class: Api::Aoa::V1::CitiesController

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

#all_cityObject



18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/api/aoa/v1/cities_controller.rb', line 18

def all_city
  {
    id: '0',
    type: 'city',
    attributes: {
      id: 0,
      name: 'All City',
    },
  }
end

#indexObject



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

def index
  cache_key = "#{CACHE_NAMESPACE}:#{self.class}:index:#{City.maximum(:updated_at)}:#{MyLocaleManager.normalize_locale}"
  my_response_cache cache_key, :json, public: true do
    today = Date.current_date
    cities = City.joins(:restaurants).
      where(restaurants: { active: true }).
      where('date(restaurants.expiry_date) >= ?', today).
      group('cities.id').
      having('count(restaurants.id) >= 10')

    cities = Api::Aoa::V1::CitySerializer.new(cities)
    { data: cities.as_json['data'].push(all_city.as_json).sort_by { |e| e['id'] } }
  end
end