Class: Api::V5::RestaurantsFilter
- Inherits:
-
Object
- Object
- Api::V5::RestaurantsFilter
- Defined in:
- app/filters/api/v5/restaurants_filter.rb
Constant Summary collapse
- TAG_CONFIG_FILTER =
%i[by_location_ids by_cuisine_ids by_facility_ids by_hashtag by_dining_style_ids].freeze
Instance Attribute Summary collapse
-
#collections ⇒ Object
, :price_range.
-
#error_message ⇒ Object
, :price_range.
-
#show_available_restaurants_only ⇒ Object
, :price_range.
-
#total_restaurants ⇒ Object
, :price_range.
Instance Method Summary collapse
-
#as_json(context, version, options = {}, channel = 'Hungry Hub') ⇒ Object
if preview_mode == true, then use Api::V5::RestaurantPreviewSerializer.
- #build_collections ⇒ Object
- #by_branch_id_eq(branch_id) ⇒ Object
- #by_city_id(city_id) ⇒ Object
- #by_date(date) ⇒ Object
- #by_dining_style_ids(params) ⇒ Object
- #by_geocode(params) ⇒ Object
- #by_group_tags(params) ⇒ Object
- #by_location_like(location) ⇒ Object
- #by_name_like(name) ⇒ Object
- #by_operator(param) ⇒ Object
- #by_package_type(package_type) ⇒ Object
- #by_people_date_time(people, date, time, package_type) ⇒ Object
-
#by_price(param) ⇒ Object
operator: lt x: 600.
- #by_price_filter(price_filter) ⇒ Object
- #by_primary_cuisine_ids(params) ⇒ Object
- #by_recommendation ⇒ Object
- #by_restaurant_tag_ids(params) ⇒ Object
- #by_section(section_no) ⇒ Object
- #by_service_type(service_type) ⇒ Object
- #by_start_time(start_time) ⇒ Object
- #by_updated_at(timestamp) ⇒ Object
- #by_user_favorite_restaurants(user_id) ⇒ Object
-
#initialize(collections = nil) ⇒ RestaurantsFilter
constructor
A new instance of RestaurantsFilter.
- #page_number(number) ⇒ Object
- #per_page(number) ⇒ Object
- #restaurant_ids=(restaurant_ids) ⇒ Object
-
#sort_by(key) ⇒ Object
`new` or `top` / `popular`.
- #use_default_collections ⇒ Object
- #valid? ⇒ Boolean
- #with_accept_voucher(accept_voucher) ⇒ Object
- #with_multiple_pricing(multiple_pricing) ⇒ Object
- #with_offer_ticket(offer_ticket) ⇒ Object
Constructor Details
#initialize(collections = nil) ⇒ RestaurantsFilter
Returns a new instance of RestaurantsFilter.
11 12 13 14 15 16 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 11 def initialize(collections = nil) self.collections = collections unless collections.nil? @valid = true @config = {} self.show_available_restaurants_only = false end |
Instance Attribute Details
#collections ⇒ Object
, :price_range
7 8 9 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 7 def collections @collections end |
#error_message ⇒ Object
, :price_range
7 8 9 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 7 def @error_message end |
#show_available_restaurants_only ⇒ Object
, :price_range
7 8 9 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 7 def show_available_restaurants_only @show_available_restaurants_only end |
#total_restaurants ⇒ Object
, :price_range
7 8 9 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 7 def total_restaurants @total_restaurants end |
Instance Method Details
#as_json(context, version, options = {}, channel = 'Hungry Hub') ⇒ Object
if preview_mode == true, then use Api::V5::RestaurantPreviewSerializer
270 271 272 273 274 275 276 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 270 def as_json(context, version, = {}, channel = 'Hungry Hub') if channel == 'AOA' as_json_aoa(context, version, ) else as_json_v5(context, version, ) end end |
#build_collections ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 278 def build_collections if @restaurant_ids.present? self.collections = ::Restaurant.includes(:translations, :restaurant_tags).where(id: @restaurant_ids) else self.collections = default_collections if collections.blank? build_by_tickets build_accept_voucher build_by_multiple_pricing build_by_home_section build_by_geocode build_by_branch_id_eq build_by_updated_at build_by_city_id build_by_package_type build_by_price build_by_filter_price build_by_service_type build_by_name_like build_by_primary_cuisine_ids # build_price_ranges build_by_user_favorite_restaurants generate_total_restaurants build_sort_by paginate collections end end |
#by_branch_id_eq(branch_id) ⇒ Object
84 85 86 87 88 89 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 84 def by_branch_id_eq(branch_id) return self if branch_id.blank? config[:by_branch_id_eq] = branch_id self end |
#by_city_id(city_id) ⇒ Object
137 138 139 140 141 142 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 137 def by_city_id(city_id) return self if city_id.blank? config[:by_city_id] = city_id self end |
#by_date(date) ⇒ Object
67 68 69 70 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 67 def by_date(date) config[:by_date] = date.to_date if date.present? self end |
#by_dining_style_ids(params) ⇒ Object
200 201 202 203 204 205 206 207 208 209 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 200 def by_dining_style_ids(params) return self if params.blank? config[:by_dining_style_ids] = if params.is_a?(String) params.split(',').map(&:to_i) else params end self end |
#by_geocode(params) ⇒ Object
77 78 79 80 81 82 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 77 def by_geocode(params) return self if params.blank? config[:by_geocode] = params self end |
#by_group_tags(params) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 108 def (params) return self if params.blank? config[:by_group_tags] = if params.is_a?(String) params.split(',').map(&:to_i) else params end self end |
#by_location_like(location) ⇒ Object
177 178 179 180 181 182 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 177 def by_location_like(location) return self if location.blank? config[:by_location_like] = location self end |
#by_name_like(name) ⇒ Object
170 171 172 173 174 175 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 170 def by_name_like(name) return self if name.blank? config[:by_name_like] = name self end |
#by_operator(param) ⇒ Object
155 156 157 158 159 160 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 155 def by_operator(param) return self if param.blank? config[:operator] = param self end |
#by_package_type(package_type) ⇒ Object
191 192 193 194 195 196 197 198 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 191 def by_package_type(package_type) return self if package_type.blank? package_type_arr = package_type.split(',') config[:by_package_type] = package_type_arr self end |
#by_people_date_time(people, date, time, package_type) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 47 def by_people_date_time(people, date, time, package_type) if Flipper.enabled? :enable_search_by_dtp adults = people.fetch(:adults, nil) kids = people.fetch(:kids, nil) config[:by_adults] = adults if adults.to_i > 0 config[:by_kids] = kids if kids.to_i > 0 by_date(date) if date.present? config[:by_time] = time if time.present? && Reservation::PERIODS.include?(time) if package_type.present? short_type = package_type.split(',').first service_type = ServiceType.short_code_to_service_type[short_type.to_sym] config[:by_service_type_edm] = service_type == :delivery ? :take_away : service_type end end self end |
#by_price(param) ⇒ Object
operator: lt x: 600
148 149 150 151 152 153 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 148 def by_price(param) return self if param.blank? config[:by_price] = param self end |
#by_price_filter(price_filter) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 228 def by_price_filter(price_filter) return self if price_filter.blank? if price_filter[:max].to_i < price_filter[:min].to_i @valid = false self. = "min can't be greater than max" end config[:price_filter] = price_filter self end |
#by_primary_cuisine_ids(params) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 126 def by_primary_cuisine_ids(params) return self if params.blank? config[:by_primary_cuisine_ids] = if params.is_a?(String) params.split(',').map(&:to_i) else params end self end |
#by_recommendation ⇒ Object
102 103 104 105 106 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 102 def by_recommendation config[:by_recommendation] = true self end |
#by_restaurant_tag_ids(params) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 91 def by_restaurant_tag_ids(params) return self if params.blank? config[:by_restaurant_tag_ids] = if params.is_a?(String) params.split(',').map(&:to_i) else params end self end |
#by_section(section_no) ⇒ Object
221 222 223 224 225 226 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 221 def by_section(section_no) return self if section_no.blank? config[:section_number] = section_no self end |
#by_service_type(service_type) ⇒ Object
184 185 186 187 188 189 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 184 def by_service_type(service_type) return self if service_type.blank? config[:by_service_type] = service_type self end |
#by_start_time(start_time) ⇒ Object
72 73 74 75 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 72 def by_start_time(start_time) config[:by_start_time] = start_time if start_time.present? && Reservation::PERIODS.include?(start_time) self end |
#by_updated_at(timestamp) ⇒ Object
119 120 121 122 123 124 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 119 def by_updated_at() return self if .blank? config[:by_updated_at] = self end |
#by_user_favorite_restaurants(user_id) ⇒ Object
32 33 34 35 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 32 def by_user_favorite_restaurants(user_id) config[:user_id] = user_id if user_id.present? self end |
#page_number(number) ⇒ Object
37 38 39 40 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 37 def page_number(number) config[:page_number] = number.to_i if number.to_i.positive? self end |
#per_page(number) ⇒ Object
42 43 44 45 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 42 def per_page(number) config[:per_page] = number.to_i if number.to_i.positive? self end |
#restaurant_ids=(restaurant_ids) ⇒ Object
23 24 25 26 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 23 def restaurant_ids=(restaurant_ids) @restaurant_ids = restaurant_ids self end |
#sort_by(key) ⇒ Object
`new` or `top` / `popular`
163 164 165 166 167 168 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 163 def sort_by(key) return self if key.blank? config[:sort_by] = key self end |
#use_default_collections ⇒ Object
18 19 20 21 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 18 def use_default_collections self.collections = default_collections.preload(pictures: :taggings) self end |
#valid? ⇒ Boolean
28 29 30 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 28 def valid? @valid end |
#with_accept_voucher(accept_voucher) ⇒ Object
254 255 256 257 258 259 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 254 def with_accept_voucher(accept_voucher) return self if accept_voucher.blank? config[:accept_voucher] = accept_voucher.to_s == 'true' self end |
#with_multiple_pricing(multiple_pricing) ⇒ Object
247 248 249 250 251 252 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 247 def with_multiple_pricing(multiple_pricing) return self if multiple_pricing.blank? config[:multiple_pricing] = multiple_pricing.to_s == 'true' self end |
#with_offer_ticket(offer_ticket) ⇒ Object
240 241 242 243 244 245 |
# File 'app/filters/api/v5/restaurants_filter.rb', line 240 def with_offer_ticket(offer_ticket) return self if offer_ticket.blank? config[:offer_ticket] = offer_ticket.to_s == 'true' self end |