Class: Api::Vendor::V1::Klook::ProductsController

Inherits:
BaseController show all
Includes:
Concerns::ErrorResponses
Defined in:
app/controllers/api/vendor/v1/klook/products_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE

Instance Attribute Summary collapse

Attributes inherited from BaseController

#vendor

Instance Method Summary collapse

Methods inherited from BaseController

#authentication

Methods included from ResponseCacheConcern

#my_response_cache

Methods included from EncryptableHelper

#decrypt, #encrypt, #generate_signature

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 LogrageCustomLogger

#append_info_to_payload

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Instance Attribute Details

#restaurantObject (readonly)

Returns the value of attribute restaurant.



5
6
7
# File 'app/controllers/api/vendor/v1/klook/products_controller.rb', line 5

def restaurant
  @restaurant
end

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
# File 'app/controllers/api/vendor/v1/klook/products_controller.rb', line 7

def index
  gzip_data = VendorsService::Klook::ProductService.new.fetch_cached_data
  response.headers['Content-Encoding'] = 'gzip'
  send_data gzip_data, type: 'application/json', disposition: 'inline'
rescue StandardError => e
  render_error(error: ApiVendorV1::Constants::KLOOK_INTERNAL_SERVER_ERROR,
               error_message: e.message, method: :index_product)
end

#showObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/api/vendor/v1/klook/products_controller.rb', line 16

def show
  BUSINESS_LOGGER.set_business_context({ restaurant_id: params[:id] })
  @restaurant = Restaurant.active.not_expired.find_by(id: params[:id])&.decorate
  raise ProductValidationError if restaurant.blank?

  cache_key = "#{CACHE_NAMESPACE}:#{self.class.name}:#{__method__}:restaurant:#{restaurant.id}:#{restaurant.cache_key}:restaurant_package:#{restaurant.restaurant_packages.cache_key}"

  my_response_cache cache_key, :json, public: true do
    serialized = Api::Vendor::V1::Klook::ProductSerializer.new(restaurant).as_json
    raise ProductValidationError if serialized[:options].blank?

    serialized
  end
rescue ProductValidationError
  render_error(error: ApiVendorV1::Constants::KLOOK_INVALID_PRODUCT_ID_ERROR,
               error_message: ApiVendorV1::Constants::KLOOK_INVALID_PRODUCT_ID_ERROR_MESSAGE,
               method: :show_product)
rescue StandardError => e
  render_error(error: ApiVendorV1::Constants::KLOOK_UNPROCESSABLE_ENTITY_ERROR,
               error_message: e.message, method: :show_product)
end