Class: Api::V6::RestaurantsController
Instance Method Summary
collapse
#identity_cache_memoization, #pagy_custom, #set_options
#append_info_to_payload
#my_response_cache
Instance Method Details
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/api/v6/restaurants_controller.rb', line 35
def hashtags
excluded_tag_ids =
AdminSetting.exclude_restaurant_tag_ids_from_hashtags_api_v6.to_s.split(',').map(&:strip).map(&:to_i)
query = @restaurant.restaurant_tags.where.not(id: excluded_tag_ids)
cache_key = "#{self.class}:hashtags:#{params}#{MyLocaleManager.normalize_locale}:#{query.cache_key}"
my_response_cache cache_key, :json, public: true do
pagy, restaurant_tags = pagy_custom(query)
RestaurantTagSerializer.new(restaurant_tags, set_options(pagy)).as_json
end
end
|
#pictures ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/api/v6/restaurants_controller.rb', line 8
def pictures
type = params[:type]
cache_key = "#{self.class}:#{@restaurant.cache_key}:pictures:#{params}#{MyLocaleManager.normalize_locale}"
my_response_cache cache_key, :json, public: true do
case type
when 'reviews'
pictures = @restaurant.review_photos.order_by_newest
meta_options = { reviews_pictures: @restaurant.review_photos_count }
when 'restaurants'
pictures = @restaurant.pictures.includes(:translations).order_by_priority
meta_options = { restaurants_pictures: @restaurant.pictures_count }
when 'all', nil, ''
pictures = all_pictures
meta_options = {
restaurants_pictures: @restaurant.pictures_count,
reviews_pictures: @restaurant.review_photos_count,
}
else
raise ApiV5::Errors::InvalidArgumentError, 'Invalid type argument'
end
pagy, pictures = pagy_array(pictures, overflow: :last_page)
RestaurantPictureSerializer.new(pictures, set_options(pagy, meta_options)).as_json
end
end
|
#reviews ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/api/v6/restaurants_controller.rb', line 48
def reviews
restaurant = Restaurant.find_by(id: params[:restaurant_id])
return render json: { success: false, message: 'Invalid Restaurant' } unless restaurant
key = restaurant.branch_id? ? :branch_id : :restaurant_id
summary = Restaurants::ReviewStat.find_by(key => restaurant.branch_id || restaurant.id)
expires_in 1.hour, public: true
render json: Api::V6::ReviewSummarySerializer.new(summary).as_json
end
|