api controller for suggesting fields

This commit is contained in:
Andrew Brown 2019-12-17 12:49:42 -06:00
parent 09aa1f239b
commit 2bcadc8ae7
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,6 @@
module Api
module V1
class ApiController
end
end
end

View File

@ -0,0 +1,23 @@
module Api
module V1
class AttributeFieldsController < ApiController
def suggest
category_label = params[:category]
entity_type = params.fetch(:entity_type, '').downcase
category_query = AttributeCategory.where(label: category_label)
category_query = category_query.where(entity_type: entity_type) unless entity_type.empty?
suggestions = AttributeField.where(attribute_category_id: category_query.pluck(:id))
.group(:label)
.order('count_id DESC')
.limit(50)
.count(:id)
.reject { |k, v| v < 10 }
.keys
render json: suggestions.to_json
end
end
end
end

View File

@ -177,6 +177,14 @@ end
end
# API Endpoints
namespace :api do
namespace :v1 do
scope '/fields' do
get '/suggest', to: 'attribute_fields#suggest'
end
end
end
scope '/generate' do
# General information