Class: Api::Aoa::V1::RestaurantsFilter
- Inherits:
-
Object
- Object
- Api::Aoa::V1::RestaurantsFilter
- Defined in:
- app/filters/api/aoa/v1/restaurants_filter.rb
Constant Summary collapse
- TAG_CONFIG_FILTER =
%i[by_location_ids by_cuisine_ids by_facility_ids by_hashtag].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 = {}) ⇒ 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_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_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
-
#initialize(collections = nil) ⇒ RestaurantsFilter
constructor
A new instance of RestaurantsFilter.
- #page_number(number) ⇒ Object
- #per_page(number) ⇒ Object
-
#sort_by(key) ⇒ Object
`new` or `top` / `popular`.
- #use_default_collections ⇒ Object
- #valid? ⇒ Boolean
- #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/aoa/v1/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/aoa/v1/restaurants_filter.rb', line 7 def collections @collections end |
#error_message ⇒ Object
, :price_range
7 8 9 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 7 def @error_message end |
#show_available_restaurants_only ⇒ Object
, :price_range
7 8 9 |
# File 'app/filters/api/aoa/v1/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/aoa/v1/restaurants_filter.rb', line 7 def total_restaurants @total_restaurants end |
Instance Method Details
#as_json(_context, _version, options = {}) ⇒ Object
if preview_mode == true, then use Api::V5::RestaurantPreviewSerializer
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 217 def as_json(_context, _version, = {}) compact_mode = [:compact_mode] == true if compact_mode [:each_serializer] ||= Api::Aoa::V1::FeaturedRestaurantSerializer coll = search_compact_restaurants(build_collections) else [:each_serializer] ||= if [:preview_mode] == true Api::Aoa::V1::RestaurantPreviewSerializer else Api::Aoa::V1::RestaurantSerializer end coll = build_collections.includes(restaurant_external: {}, restaurant_packages: :package) end = { serialization_context: [:serialization_context], minor_version: [:minor_version], package_type: config[:by_package_type], } serializer = [:each_serializer].new(coll, ) serializer.as_json end |
#build_collections ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 242 def build_collections self.collections = default_collections if collections.nil? build_by_tickets 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_sort_by build_by_name_like build_by_primary_cuisine_ids # build_by_date_time # build_price_ranges generate_total_restaurants paginate collections end |
#by_branch_id_eq(branch_id) ⇒ Object
54 55 56 57 58 59 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 54 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
107 108 109 110 111 112 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 107 def by_city_id(city_id) return self if city_id.blank? config[:by_city_id] = city_id self end |
#by_date(date) ⇒ Object
37 38 39 40 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 37 def by_date(date) config[:by_date] = date.to_date if date.present? self end |
#by_geocode(params) ⇒ Object
47 48 49 50 51 52 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 47 def by_geocode(params) return self if params.blank? config[:by_geocode] = params self end |
#by_group_tags(params) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 78 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
147 148 149 150 151 152 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 147 def by_location_like(location) return self if location.blank? config[:by_location_like] = location self end |
#by_name_like(name) ⇒ Object
140 141 142 143 144 145 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 140 def by_name_like(name) return self if name.blank? config[:by_name_like] = name self end |
#by_operator(param) ⇒ Object
125 126 127 128 129 130 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 125 def by_operator(param) return self if param.blank? config[:by_operator] = param self end |
#by_package_type(package_type) ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 161 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_price(param) ⇒ Object
operator: lt x: 600
118 119 120 121 122 123 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 118 def by_price(param) return self if param.blank? config[:by_price] = param self end |
#by_price_filter(price_filter) ⇒ Object
187 188 189 190 191 192 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 187 def by_price_filter(price_filter) return self if price_filter.blank? config[:price_filter] = price_filter self end |
#by_primary_cuisine_ids(params) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 96 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
72 73 74 75 76 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 72 def by_recommendation config[:by_recommendation] = true self end |
#by_restaurant_tag_ids(params) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 61 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
180 181 182 183 184 185 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 180 def by_section(section_no) return self if section_no.blank? config[:section_number] = section_no self end |
#by_service_type(service_type) ⇒ Object
154 155 156 157 158 159 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 154 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
42 43 44 45 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 42 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
89 90 91 92 93 94 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 89 def by_updated_at() return self if .blank? config[:by_updated_at] = self end |
#page_number(number) ⇒ Object
27 28 29 30 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 27 def page_number(number) config[:page_number] = number.to_i if number.to_i.positive? self end |
#per_page(number) ⇒ Object
32 33 34 35 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 32 def per_page(number) config[:per_page] = number.to_i if number.to_i.positive? self end |
#sort_by(key) ⇒ Object
`new` or `top` / `popular`
133 134 135 136 137 138 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 133 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/aoa/v1/restaurants_filter.rb', line 18 def use_default_collections self.collections = default_collections.preload(pictures: :taggings) self end |
#valid? ⇒ Boolean
23 24 25 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 23 def valid? @valid end |
#with_multiple_pricing(multiple_pricing) ⇒ Object
201 202 203 204 205 206 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 201 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
194 195 196 197 198 199 |
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 194 def with_offer_ticket(offer_ticket) return self if offer_ticket.blank? config[:offer_ticket] = offer_ticket.to_s == 'true' self end |