Class: Admin::Restaurants::RestaurantTagsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Admin::Restaurants::RestaurantTagsController
- Defined in:
- app/controllers/admin/restaurants/restaurant_tags_controller.rb
Overview
Responsible to manage restaurant's tag
Constant Summary
Constants inherited from BaseController
BaseController::INTERNAL_SERVER_ERROR_MESSAGE
Instance Attribute Summary collapse
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
Instance Method Summary collapse
Methods inherited from BaseController
#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session
Methods included from LogrageCustomLogger
Methods included from AdminHelper
#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?
Methods included from UpdateLocaleConcern
Methods inherited from ApplicationController
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Attribute Details
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
10 11 12 |
# File 'app/controllers/admin/restaurants/restaurant_tags_controller.rb', line 10 def restaurant @restaurant end |
Instance Method Details
#create_or_update_bulk ⇒ Object
30 31 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 60 61 62 63 |
# File 'app/controllers/admin/restaurants/restaurant_tags_controller.rb', line 30 def create_or_update_bulk restaurant..each do |tag| restaurant..delete tag.id end params.require(:restaurant_tags).permit(tags: [:label, :value])[:tags].values.each do |tag| restaurant_tag = if tag.key?('value') && tag['value'].to_i.positive? RestaurantTag.fetch(tag['value']) else title = "Hashtags:#{tag['label']}" RestaurantTag.find_or_create_by(title_en: title, title_th: title) end restaurant. << restaurant_tag end = restaurant..map do |tag| { label: tag.title_format('en'), value: tag.id, } end if restaurant.bookable_and_not_expired? EventDrivenWorkers::HhSearch::ProducerWorker.perform_async( EventDrivenClient::Constants::RESTAURANTS_TOPIC, EventDrivenClient::Constants::UPDATE_EVENT, restaurant.id, { hashtags: {} }, { source: 'Admin::Restaurants::RestaurantTagsController#create_or_update_bulk' }, ) end render json: end |
#destroy_all ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/admin/restaurants/restaurant_tags_controller.rb', line 65 def destroy_all restaurant..each do |tag| restaurant..delete(tag.id) end if restaurant.bookable_and_not_expired? EventDrivenWorkers::HhSearch::ProducerWorker.perform_async( EventDrivenClient::Constants::RESTAURANTS_TOPIC, EventDrivenClient::Constants::UPDATE_EVENT, restaurant.id, { hashtags: {} }, { source: 'Admin::Restaurants::RestaurantTagsController#destroy_all' }, ) end render json: { success: true } end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/admin/restaurants/restaurant_tags_controller.rb', line 12 def index = if params[:category].present? restaurant..where_category(params[:category]) else restaurant. end if params[:serializer] == 'dropdown' = .map do |tag| { label: tag.title_format(params.require(:tag_locale)), value: tag.id, } end end render json: end |