cartodb-4.42/app/controllers/carto/api/search_preview_presenter.rb
2024-04-06 05:25:13 +00:00

32 lines
833 B
Ruby

class Carto::Api::SearchPreviewPresenter
def initialize(dashboard_search_result:, limit:, current_viewer:, context:)
@dashboard_search_result = dashboard_search_result
@limit = limit
@current_viewer = current_viewer
@context = context
end
def to_poro
result = (poro_tags + poro_visualizations).first(@limit)
{
result: result,
total_count: @dashboard_search_result.total_count
}
end
private
def poro_tags
@dashboard_search_result.tags.map do |tag|
Carto::Api::TagPresenter.new(tag, @current_viewer, @context).to_search_preview_poro
end
end
def poro_visualizations
@dashboard_search_result.visualizations.map do |visualization|
Carto::Api::VisualizationPresenter.new(visualization, @current_viewer, @context).to_search_preview_poro
end
end
end