Class: HousingMisc::ModelReflectionsController

Inherits:
ApplicationController show all
Includes:
ApiHelper, ModelsReflectionsHelper
Defined in:
app/controllers/housing_misc/model_reflections_controller.rb

Constant Summary

Constants included from ApiHelper

ApiHelper::MOBILE_REQUEST_TIME_THRESHOLD

Constants included from ModelsReflectionsHelper

ModelsReflectionsHelper::VAL_HASH_KEYS

Instance Method Summary collapse

Methods included from ApiHelper

#add_attachments, #add_base_vars, #add_global_merge_vars, #add_merge_vars, #add_user_emails, #csrf_check, #filter_parameters, #get_api_call, #get_email_template_from_mail_service, #get_past_channel_details, #get_request_attribute_value, #get_shortened_url, #internal_host_check, #is_request_csrf_valid?, #is_request_from_mobile?, #is_request_internal?, #log_invalid_csrf_request, #logging_file, #send_generic_mail, #send_generic_sms, #upload_log_to_s3

Methods included from ModelsReflectionsHelper

#convert_rows_to_col, #get_join_table_name, #get_model_reflections, #get_primary_key, #get_table_names_primary_keys_and_model_names, #tables_reflections_hash_generator, #update_base_models

Methods inherited from ApplicationController

#new_relic_custom_params

Methods inherited from ActionController::Base

#render

Instance Method Details

#check_permissionObject



8
9
10
# File 'app/controllers/housing_misc/model_reflections_controller.rb', line 8

def check_permission
  return false
end

#models_reflections_generatorObject

Author Prabal Partap

<b>Date</b>5 March, 2019
<b>Short Description</b> Api to get reflections(associations) of the given models and also the models associated with those models(found in reflections of those models) 
<b>Endpoints</b> Database Prunning Service
<b>Request Type</b> GET
<b>Route </b> /model_reflections
<b>Authentication Required</b> its an internal API hence no authentication
<b>Request Format</b>
{
  "models" : "WhatsappPermission,SmsRequest"
}
<b>unsuccesful Response</b>
{
  "message" : "Bad request",
  "error" : "incorrect model names, don't give spaces after model names"
}
<b>succesful Response</b>
{
  "message": "succesful",
  "error": "",
  {
    "whatsapp_permissions": {
      "subscriptions": {
        "table_name": "subscriptions",
        "macros": [
            "belongs_to"
        ],
        "throughs": [
           "FALSE"
        ],
        "foreign_keys": [
          "number"
        ],
        "primary_keys": [
          "number"
        ],
        "model_name": "Subscription"
      }
    },
    "sms_requests": {
      "statuses": {
        "table_name": "statuses",
        "macros": [
          "belongs_to"
        ],
        "throughs": [
          "FALSE"
        ],
        "foreign_keys": [
          "status_id"
        ],
        "primary_keys": [
          "id"
        ],
        "model_name": "::Status"
      },
      "sms_templates": {
        "table_name": "sms_templates",
        "macros": [
          "belongs_to"
        ],
        "throughs": [
          "FALSE"
        ],
        "foreign_keys": [
          "template_id"
        ],
        "primary_keys": [
          "id"
        ],
        "model_name": "::SmsTemplate"
      }
    },
    "subscriptions": {
      "whatsapp_permissions": {
        "table_name": "whatsapp_permissions",
        "macros": [
          "has_many"
        ],
        "throughs": [
          "FALSE"
        ],
        "foreign_keys": [
          "number"
        ],
        "primary_keys": [
          "number"
        ],
        "model_name": "WhatsappPermission"
      }
    },
    "statuses": {},
    "sms_templates": {
      "gateway_types": {
        "table_name": "gateway_types",
        "macros": [
          "belongs_to"
        ],
        "throughs": [
          "FALSE"
        ],
        "foreign_keys": [
          "gateway_type_id"
        ],
        "primary_keys": [
          "id"
        ],
        "model_name": "GatewayType"
      }
    },
    "gateway_types": {
      "sms_templates": {
        "table_name": "sms_templates",
        "macros": [
          "has_many"
        ],
        "throughs": [
          "FALSE"
        ],
        "foreign_keys": [
          "gateway_type_id"
        ],
        "primary_keys": [
          "id"
        ],
        "model_name": "SmsTemplate"
      }
    }
  }
}


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/housing_misc/model_reflections_controller.rb', line 145

def models_reflections_generator
  base_models = filter_params['models'].split(',')
  base_tables = []
  table_name = ""
  base_models.each do |model|
    table_name = model.constantize.table_name rescue "Invalid_Table"
    break if table_name == "Invalid_Table" 
    base_tables.push(table_name)
  end
  if table_name == 'Invalid_Table'
    render json: {message: "incorrect model names, don't give spaces after model names"},status: :bad_request
  else
    tables_reflections_hash = tables_reflections_hash_generator(base_models)
    render json: tables_reflections_hash, status: :ok 
  end
end