Class: Api::V5::AdaptivePointsController
Constant Summary
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary
collapse
#identity_cache_memoization
#append_info_to_payload
#my_response_cache
Instance Method Details
#adaptive_points_ratio_by_group(restaurant) ⇒ Object
17
18
19
20
21
22
23
|
# File 'app/controllers/api/v5/adaptive_points_controller.rb', line 17
def adaptive_points_ratio_by_group(restaurant)
group_id = restaurant.restaurant_group_id
ratio = AdaptivePointsRatio.find_by(campaign_id: group_id, is_active: true)
return ratio.slice(:id, :points_value, :baht_value) if ratio
adaptive_points_ratio_by_tag(restaurant)
end
|
#adaptive_points_ratio_by_tag(restaurant) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'app/controllers/api/v5/adaptive_points_controller.rb', line 25
def adaptive_points_ratio_by_tag(restaurant)
tag_ids = restaurant.hashtag_tags.pluck(:id)
ratio = AdaptivePointsRatio.where(campaign_id: tag_ids, is_active: true).order('baht_value ASC').last
return ratio.slice(:id, :points_value, :baht_value) if ratio
{ id: nil, points_value: 1, baht_value: 1 }
end
|
#find_adaptive_points_ratio(restaurant) ⇒ Object
10
11
12
13
14
15
|
# File 'app/controllers/api/v5/adaptive_points_controller.rb', line 10
def find_adaptive_points_ratio(restaurant)
ratio = AdaptivePointsRatio.find_by(campaign_id: restaurant.id, is_active: true)
return ratio.slice(:id, :points_value, :baht_value) if ratio
adaptive_points_ratio_by_group(restaurant)
end
|
#index ⇒ Object
Prioritize restaurant > restaurant group > restaurant tag
4
5
6
7
8
|
# File 'app/controllers/api/v5/adaptive_points_controller.rb', line 4
def index
restaurant = Restaurant.fetch(params.require(:restaurant_id))
adaptive_points_ratio = find_adaptive_points_ratio(restaurant)
render json: { success: true, data: adaptive_points_ratio }
end
|