Class: Api::Aoa::V1::CitiesController
Constant Summary
BaseController::CACHE_NAMESPACE
Instance Method Summary
collapse
#identity_cache_memoization
#append_info_to_payload
#my_response_cache
Instance Method Details
#all_city ⇒ Object
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
|
#index ⇒ Object
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
|