Class: Api::Admin::RestaurantsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/admin/restaurants_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#identity_cache_memoization, #set_app_language

Methods included from LogrageCustomLogger

#append_info_to_payload

Instance Method Details

#createObject



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/api/admin/restaurants_controller.rb', line 5

def create
  HH_LOGGER.info('Restaurant API creation started', { params: restaurant_params.inspect })

  begin
    HH_LOGGER.info('Calling restaurant creation service')
    result = RestaurantService::CreateFromApi.new(params: restaurant_params).execute!
    HH_LOGGER.info('Restaurant creation service completed', { success: result.success?, message: result.message })

    if result.success?
      render_success(
        data: serialize_restaurant_response(result),
        message: 'Restaurant created successfully',
        status: :created,
      )
    else
      render_error(
        message: result.message || 'Failed to create restaurant',
        errors: result.errors || [],
        status: :unprocessable_entity,
      )
    end
  rescue ActionController::ParameterMissing => e
    HH_LOGGER.error('Restaurant API parameter missing', { error: e.message, params: params })
    render_error(
      message: e.message,
      errors: [],
      status: :bad_request,
    )
  rescue StandardError => e
    HH_LOGGER.error('Restaurant API unexpected error', {
                      error: e.class.name,
                      message: e.message,
                      backtrace: e.backtrace.first(10),
                    })
    render_error(
      message: "Something went wrong during restaurant creation: #{e.message}",
      errors: [],
      status: :internal_server_error,
    )
  end
end