mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
api controller for suggesting fields
This commit is contained in:
parent
09aa1f239b
commit
2bcadc8ae7
6
app/controllers/api/v1/api_controller.rb
Normal file
6
app/controllers/api/v1/api_controller.rb
Normal file
@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class ApiController
|
||||
end
|
||||
end
|
||||
end
|
||||
23
app/controllers/api/v1/attribute_fields_controller.rb
Normal file
23
app/controllers/api/v1/attribute_fields_controller.rb
Normal 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
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user