Class: Api::Aoa::V1::RestaurantsFilter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#collectionsObject

, :price_range



7
8
9
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 7

def collections
  @collections
end

#error_messageObject

, :price_range



7
8
9
# File 'app/filters/api/aoa/v1/restaurants_filter.rb', line 7

def error_message
  @error_message
end

#show_available_restaurants_onlyObject

, :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_restaurantsObject

, :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

Examples:

options = {
  preview_mode: true || false
}

Parameters:

  • context (Struct)

    Serialization Context

  • version (Integer)

    ApiV5::Constants::DEFAULT_MINOR_VERSION

  • options (Hash) (defaults to: {})
    • include options to be passed to Serializer instance



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, options = {})
  compact_mode = options[:compact_mode] == true

  if compact_mode
    options[:each_serializer] ||= Api::Aoa::V1::FeaturedRestaurantSerializer
    coll = search_compact_restaurants(build_collections)
  else
    options[:each_serializer] ||= if options[:preview_mode] == true
                                    Api::Aoa::V1::RestaurantPreviewSerializer
                                  else
                                    Api::Aoa::V1::RestaurantSerializer
                                  end
    coll = build_collections.includes(restaurant_external: {}, restaurant_packages: :package)
  end

  serializer_options = {
    serialization_context: options[:serialization_context],
    minor_version: options[:minor_version],
    package_type: config[:by_package_type],
  }

  serializer = options[:each_serializer].new(coll, serializer_options)
  serializer.as_json
end

#build_collectionsObject



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_group_tags
  build_by_restaurant_tags
  build_by_name_like
  old_build_by_restaurant_tags
  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 by_group_tags(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

Parameters:

  • param (String)

    :lt, :gt, :lte, :gte, :between



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_recommendationObject



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(timestamp)
  return self if timestamp.blank?

  config[:by_updated_at] = timestamp
  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_collectionsObject



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

Returns:

  • (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