Module: EventDrivenServices::HhSearch::Helpers::RestaurantTagHelper
- Included in:
- Producers::RestaurantTagProducer, Schemas::RestaurantTagSchema
- Defined in:
- app/services/event_driven_services/hh_search/helpers/restaurant_tag_helper.rb
Instance Method Summary collapse
-
#restaurant_tags_with_min_one_tagged_active_restaurants ⇒ ActiveRecord::Relation
Get all restaurant tags that have at least one tagged restaurants.
-
#total_restaurants_for_all_cities(restaurant_tag) ⇒ Integer
Get the total number of restaurants that tagged with the restaurant_tag.
Instance Method Details
#restaurant_tags_with_min_one_tagged_active_restaurants ⇒ ActiveRecord::Relation
Get all restaurant tags that have at least one tagged restaurants
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/event_driven_services/hh_search/helpers/restaurant_tag_helper.rb', line 9 def # Get current time in UTC current_time = Time.now.utc # Join with active RestaurantTagsRestaurant associations = RestaurantTag.joins(restaurant_tags_restaurants: :restaurant). where(restaurants: { active: true }). where('restaurants.expiry_date >= ?', current_time) # Join with active PrimaryTag associations = RestaurantTag.joins(primary_tags: :restaurant). where(restaurants: { active: true }). where('restaurants.expiry_date >= ?', current_time) # Perform a union of both associations and ensure uniqueness .union().distinct end |
#total_restaurants_for_all_cities(restaurant_tag) ⇒ Integer
Get the total number of restaurants that tagged with the restaurant_tag
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/services/event_driven_services/hh_search/helpers/restaurant_tag_helper.rb', line 32 def total_restaurants_for_all_cities(restaurant_tag) return 0 if restaurant_tag.blank? return 0 unless restaurant_tag.is_a?(RestaurantTag) # Get current time in UTC current_time = Time.now.utc # Query for restaurant_tags_restaurants = RestaurantTagsRestaurant.joins(:restaurant). where(restaurant_tag_id: restaurant_tag.id). where('restaurants.expiry_date >= ?', current_time). where(restaurants: { active: true }). distinct = .count('restaurants.id') # Query for primary_tags = PrimaryTag.joins(:restaurant). where(restaurant_tag_id: restaurant_tag.id). where('restaurants.expiry_date >= ?', current_time). where(restaurants: { active: true }). where.not(restaurant_id: .select(:restaurant_id)). distinct. count('restaurants.id') # Return the total count of restaurants that tagged with the restaurant_tag + end |