Class: Api::V5::RestaurantPackagesFilter
- Inherits:
-
Object
- Object
- Api::V5::RestaurantPackagesFilter
- Includes:
- PaginationConcernFilter
- Defined in:
- app/filters/api/v5/restaurant_packages_filter.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
Instance Method Summary collapse
- #as_json(context, version, options = {}) ⇒ Object
- #by_city_id(city_id) ⇒ Object
- #by_updated_at(timestamp) ⇒ Object
- #exclude_nil_rank(yes) ⇒ Object
- #init_default ⇒ Object
-
#initialize(collections = nil) ⇒ RestaurantPackagesFilter
constructor
A new instance of RestaurantPackagesFilter.
- #remove_hah_packages ⇒ Object
-
#sort_by(key) ⇒ Object
currently only support sort by `rank`.
Methods included from PaginationConcernFilter
Constructor Details
#initialize(collections = nil) ⇒ RestaurantPackagesFilter
Returns a new instance of RestaurantPackagesFilter.
9 10 11 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 9 def initialize(collections = nil) self.collections = collections unless collections.nil? end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
7 8 9 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 7 def collections @collections end |
Instance Method Details
#as_json(context, version, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 62 def as_json(context, version, = {}) [:each_serializer] = Api::V5::RestaurantPackageSerializer col = collections.compact if col.present? ActiveModelSerializers::SerializableResource.new(col, { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, minor_version: version }.merge() ).as_json else { data: [] } end end |
#by_city_id(city_id) ⇒ Object
35 36 37 38 39 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 35 def by_city_id(city_id) return self if city_id.blank? self.collections = collections.where("#{Restaurant.table_name}.city_id = ?", city_id) self end |
#by_updated_at(timestamp) ⇒ Object
29 30 31 32 33 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 29 def by_updated_at() return self if .blank? self.collections = collections.where("#{HhPackage::RestaurantPackage.table_name}.updated_at >= ?", ) self end |
#exclude_nil_rank(yes) ⇒ Object
49 50 51 52 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 49 def exclude_nil_rank(yes) self.collections = collections.where("#{HhPackage::RestaurantPackage.table_name}.rank IS NOT NULL") if yes self end |
#init_default ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 13 def init_default today = Time.zone.now.to_date self.collections = HhPackage::RestaurantPackage.joins(:restaurant) .where(deleted_at: nil, active: true).where('end_date >= ?', today) .where('restaurants.active = ?', true) .includes(package: %i[translations pricing], restaurant: %i[translations restaurant_tags]) self end |
#remove_hah_packages ⇒ Object
24 25 26 27 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 24 def remove_hah_packages self.collections = collections.where.not(package_type: HhPackage::Package::HungryAtHome.to_s) self end |
#sort_by(key) ⇒ Object
currently only support sort by `rank`
42 43 44 45 46 47 |
# File 'app/filters/api/v5/restaurant_packages_filter.rb', line 42 def sort_by(key) return self if key.blank? self.collections = collections.order("#{HhPackage::RestaurantPackage.table_name}.rank ASC") if key.to_s == 'rank' self end |