notebook/app/controllers/api/v1/attribute_fields_controller.rb
2019-12-17 17:36:41 -06:00

23 lines
678 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, '').downcase
).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