Class: Api::Vendor::V1::CuisinesFilter
- Inherits:
-
Object
- Object
- Api::Vendor::V1::CuisinesFilter
- Includes:
- Api::V5::PaginationConcernFilter
- Defined in:
- app/filters/api/vendor/v1/cuisines_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
- #init_default ⇒ Object
-
#initialize(collections = nil) ⇒ CuisinesFilter
constructor
A new instance of CuisinesFilter.
- #sort_by(key) ⇒ Object
Methods included from Api::V5::PaginationConcernFilter
Constructor Details
#initialize(collections = nil) ⇒ CuisinesFilter
Returns a new instance of CuisinesFilter.
11 12 13 14 15 16 17 |
# File 'app/filters/api/vendor/v1/cuisines_filter.rb', line 11 def initialize(collections = nil) unless collections.nil? self.collections = collections.select("#{RestaurantTag.table_name}.*").select('COUNT(*) AS total_restaurants').joins(:restaurants).where('title_en LIKE ?', 'Cuisine:%').where(restaurants: { active: true }). where('date(restaurants.expiry_date) >= ?', Time.thai_time.to_date). group('restaurant_tags.id') end end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
8 9 10 |
# File 'app/filters/api/vendor/v1/cuisines_filter.rb', line 8 def collections @collections end |
Instance Method Details
#as_json(context, _version, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'app/filters/api/vendor/v1/cuisines_filter.rb', line 58 def as_json(context, _version, = {}) [:each_serializer] = Api::Vendor::V1::CuisineSerializer ActiveModelSerializers::SerializableResource.new(collections, { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, }.merge()).as_json end |
#by_city_id(city_id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/filters/api/vendor/v1/cuisines_filter.rb', line 26 def by_city_id(city_id) return self if city_id.blank? self.collections = collections.where(restaurants: { city_id: city_id, }) self end |
#init_default ⇒ Object
19 20 21 22 23 24 |
# File 'app/filters/api/vendor/v1/cuisines_filter.rb', line 19 def init_default self.collections = RestaurantTag.select("#{RestaurantTag.table_name}.*").select('COUNT(*) AS total_restaurants').joins(:restaurants).where('title_en LIKE ?', 'Cuisine:%').where(restaurants: { active: true }). where('date(restaurants.expiry_date) >= ?', Time.thai_time.to_date). group('restaurant_tags.id') self end |
#sort_by(key) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/filters/api/vendor/v1/cuisines_filter.rb', line 35 def sort_by(key) return self if key.blank? case key.to_s when 'name_asc' self.collections = collections.order("title_#{MyLocaleManager.normalize_locale} ASC") when 'name_desc' self.collections = collections.order("title_#{MyLocaleManager.normalize_locale} DESC") when 'total_restaurants_asc' self.collections = collections.order('total_restaurants ASC') when 'total_restaurants_desc' self.collections = collections.order('total_restaurants DESC') end self end |