<commit_before>class InventoryApi::V1::AssetsController < Api::ApiController

  before_action :cors_set_access_control_headers

  def cors_set_access_control_headers
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
    headers['Access-Control-Allow-Headers'] = '*'
    headers['Access-Control-Max-Age'] = "1728000"
  end

  def index
    orgs = current_user.viewable_organizations
    response  = TransamAsset.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
    render status: 200, json: response
  end

  def all
    # # check for groupkey, if so return empty
    # #TransitAsset.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # response  =
    # RevenueVehicle.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # .concat(
    #   CapitalEquipment.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # ).concat(
    #   Facility.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # )#.concat(
    # #   ServiceVehicle.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # # )
    # render status: 200, json: response


    orgs = current_user.viewable_organizations

    asset_type = get_assets_params[:type]

    case asset_type[:val].parameterize.underscore
      when "revenue_vehicles"
        response = RevenueVehicle.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
      when "capital_equipment"
        response = CapitalEquipment.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
      when "facilities"
        response = Facility.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
      when "service_vehicles"
        response = ServiceVehicle.where(organization: orgs, service_vehiclible_type: nil).map{ |asset| asset.very_specific.inventory_api_json }
      else
        #return all assets
        response  = TransamAsset.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
    end

    render status: 200, json: response
  end

  def properties
    response = {
      "schema": {
        "type": "object",
        "properties": {
          "type": {
            "enum": ["Revenue Vehicles", "Service Vehicles", "Facilities", "Capital Equipment"],#AssetType.all.pluck(:name),
            "tuple": [{id: 1, val: "Revenue Vehicles"}, {id: 2, val: "Service Vehicles"},  {id: 3, val: "Facilities"},  {id: 4, val:"Capital Equipment"}],# Asset IDs here are ARBITRARY. we made them up, because the supported 'asset type' options listed here don't correspond to any actual attribute or model.
            "type": "string",
            "title": "Type"
          }
        }
      },
      "uiSchema": {}
    }
    render status: 200, json: response
  end

  def post_profile
    asset_type = profile_params[:type]
    case asset_type[:val].parameterize.underscore
      when "revenue_vehicle"
        response = RevenueVehicle.bulk_updates_profile
      when "equipment"<commit_msg>Update assets_controller.rb<commit_after>class InventoryApi::V1::AssetsController < Api::ApiController

  before_action :cors_set_access_control_headers

  def cors_set_access_control_headers
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
    headers['Access-Control-Allow-Headers'] = '*'
    headers['Access-Control-Max-Age'] = "1728000"
  end

  def index
    orgs = current_user.viewable_organizations
    response  = TransamAsset.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
    render status: 200, json: response
  end

  def all
    # # check for groupkey, if so return empty
    # #TransitAsset.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # response  =
    # RevenueVehicle.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # .concat(
    #   CapitalEquipment.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # ).concat(
    #   Facility.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # )#.concat(
    # #   ServiceVehicle.limit(10).map{ |asset| asset.very_specific.inventory_api_json }
    # # )
    # render status: 200, json: response


    orgs = current_user.viewable_organizations

    asset_type = get_assets_params[:type]

    case asset_type[:val].parameterize.underscore
      when "revenue_vehicles"
        response = RevenueVehicle.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
      when "capital_equipment"
        response = CapitalEquipment.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
      when "facilities"
        response = Facility.where(organization: orgs).map{ |asset| asset.very_specific.inventory_api_json }
      when "service_vehicles"
        response = ServiceVehicle.where(organization: orgs, service_vehiclible_type: nil).map{ |asset| asset.very_specific.inventory_api_json }
      else
        #return all assets
        response  = TransamAsset.where(organization: orgs).map{ |asset|
          Rails.cache.read(asset.id)
#          asset.very_specific.inventory_api_json

        }
    end

    render status: 200, json: response
  end

  def properties
    response = {
      "schema": {
        "type": "object",
        "properties": {
          "type": {
            "enum": ["Revenue Vehicles", "Service Vehicles", "Facilities", "Capital Equipment"],#AssetType.all.pluck(:name),
            "tuple": [{id: 1, val: "Revenue Vehicles"}, {id: 2, val: "Service Vehicles"},  {id: 3, val: "Facilities"},  {id: 4, val:"Capital Equipment"}],# Asset IDs here are ARBITRARY. we made them up, because the supported 'asset type' options listed here don't correspond to any actual attribute or model.
            "type": "string",
            "title": "Type"
          }
        }
      },
      "uiSchema": {}
    }
    render status: 200, json: response
  end

  def post_profile
    asset_type = profile_params[:type]
    case asset_type[:val].parameterize.underscore
      when "revenue_vehicle"
        response = RevenueVehicle.bulk_updates_profile
      when "equipment"
{'fraction_non_alphanumeric': 0.11771282542724805, 'fraction_numerical': 0.01086088484267689, 'mean_word_length': 3.422316384180791, 'pattern_counts': {'":': 18, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '822198', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1927, 'n_words': 399}