notebook/app/controllers/api/v1/attribute_fields_controller.rb
2020-01-03 12:09:47 -06:00

23 lines
702 B
Ruby

module Api
module V1
class AttributeFieldsController < ApiController
def suggest
suggestions = AttributeFieldSuggestion.where(
entity_type: params.fetch(:entity_type, '').downcase,
category_label: params.fetch(:category, '')
).where.not(suggestion: [nil, ""]).order('weight desc').limit(
AttributeFieldSuggestion::SUGGESTIONS_RESULT_COUNT
).pluck(:suggestion)
if suggestions.empty?
CacheMostUsedAttributeFieldsJob.perform_later(
params.fetch(:entity_type, nil),
params.fetch(:category, nil)
)
end
render json: suggestions.to_json
end
end
end
end