Class: Api::Partner::V1::BenchmarkController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/partner/v1/benchmark_controller.rb

Overview

Controller for benchmark data API Provides performance comparison data for restaurants against competitors and tags

Examples:

GET /api/partner/v1/benchmark

GET /api/partner/v1/benchmark?data_view_type=monthly&start_month=2025-01&end_month=2025-06&data_type=all
GET /api/partner/v1/benchmark?data_view_type=weekly&start_date=2025-01-01&end_date=2025-02-15&data_type=competitor

Instance Method Summary collapse

Methods inherited from BaseController

#default_restaurant, #identity_cache_memoization, #render_unauthorize_action, #restaurants, #set_options

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#indexJSON

GET /api/partner/v1/benchmark

Query Parameters:

  • data_view_type (required): 'monthly' or 'weekly'

  • data_type (required): 'all', 'tags', or 'competitor'

  • For monthly view:

    • start_month (required): YYYY-MM format

    • end_month (required): YYYY-MM format

  • For weekly view:

    • start_date (required): YYYY-MM-DD format

    • end_date (required): YYYY-MM-DD format

Returns:

  • (JSON)

    Benchmark data with performance and avg spend reports



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/api/partner/v1/benchmark_controller.rb', line 24

def index
  return unless validate_params!

  service = PartnerService::Benchmark::CalculateService.new(
    restaurant: current_restaurant,
    restaurants: current_staff.restaurants,
    data_view_type: params[:data_view_type],
    data_type: params[:data_type],
    start_date: params[:start_date],
    end_date: params[:end_date],
    start_month: params[:start_month],
    end_month: params[:end_month],
  )

  if service.valid?
    data = service.call
    render json: { success: true, data: data }
  else
    render json: { success: false, message: service.error_messages }, status: :bad_request
  end
end