Class: Api::Vendor::V1::ReviewsController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::PaginationParam
Defined in:
app/controllers/api/vendor/v1/reviews_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE

Instance Attribute Summary

Attributes inherited from BaseController

#vendor

Instance Method Summary collapse

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#blogger_reviewObject



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
# File 'app/controllers/api/vendor/v1/reviews_controller.rb', line 33

def blogger_review
  restaurant_id = params.require(:restaurant_id)
  restaurant = Restaurant.active.not_expired.where(id: restaurant_id).first
  raise ApiVendorV1::Errors::RestaurantValidationError if restaurant.blank?

  filter = Api::Vendor::V1::ReviewsFilter.new
  filter.restaurant_id = restaurant.id
  filter.scope_by_blogger(restaurant_id: restaurant.id, branch_id: restaurant.branch_id)
  filter.page_number(page_number_param).
    per_page(page_size_param).
    use_default_order.
    sort_by(params[:sort])

  my_response_cache(filter.collections.cache_key, :json, public: true) do
    serialized_data = Api::Vendor::V1::BloggerReviewSerializer.new(filter.collections).serializable_hash

    # Construct the response data
    {
      success: true,
      message: nil,
      data: serialized_data[:data],
    }
  end
rescue ApiVendorV1::Errors::RestaurantValidationError
  render_error_response(error_message: ApiVendorV1::Constants::VENDOR_RESTAURANT_VALIDATION_ERROR)
rescue ActionController::ParameterMissing => e
  render_error_response(error_message: e.message)
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/api/vendor/v1/reviews_controller.rb', line 5

def index
  restaurant_id = params.require(:restaurant_id)
  restaurant = Restaurant.active.not_expired.where(id: restaurant_id).first
  raise ApiVendorV1::Errors::RestaurantValidationError if restaurant.blank?

  filter = Api::Vendor::V1::ReviewsFilter.new
  filter.scope_by(restaurant_id: restaurant.id, branch_id: restaurant.branch_id)
  filter.page_number(page_number_param).
    per_page(page_size_param).
    use_default_order.
    sort_by(params[:sort])

  my_response_cache(filter.collections.cache_key, :json, public: true) do
    serialized_data = Api::Vendor::V1::ReviewSerializer.new(filter.collections).serializable_hash

    # Construct the response data
    {
      success: true,
      message: nil,
      data: serialized_data[:data],
    }
  end
rescue ApiVendorV1::Errors::RestaurantValidationError
  render_error_response(error_message: ApiVendorV1::Constants::VENDOR_RESTAURANT_VALIDATION_ERROR)
rescue ActionController::ParameterMissing => e
  render_error_response(error_message: e.message)
end