2024-06-04 10:43:37 +02:00
|
|
|
class API::Public::V1::BaseController < ApplicationController
|
2023-01-03 14:46:10 +01:00
|
|
|
skip_forgery_protection
|
|
|
|
|
2023-01-20 14:28:02 +01:00
|
|
|
before_action :check_content_type_is_json, if: -> { request.post? || request.patch? || request.put? }
|
2023-01-03 14:46:10 +01:00
|
|
|
|
2024-06-04 10:43:37 +02:00
|
|
|
before_action do
|
|
|
|
Current.browser = 'api'
|
|
|
|
end
|
|
|
|
|
2023-01-03 14:46:10 +01:00
|
|
|
protected
|
|
|
|
|
|
|
|
def render_missing_param(param_name)
|
|
|
|
render_error("#{param_name} is missing", :bad_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_bad_request(error_message)
|
|
|
|
render_error(error_message, :bad_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_not_found(resource_name, resource_id)
|
|
|
|
render_error("#{resource_name} #{resource_id} is not found", :not_found)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_content_type_is_json
|
|
|
|
render_error("Content-Type should be json", :bad_request) unless request.headers['Content-Type'] == 'application/json'
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_error(message, status)
|
|
|
|
render json: { error: message }, status: status
|
|
|
|
end
|
|
|
|
end
|