Skip to content

Commit

Permalink
feature: process search results (#3310)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Oct 5, 2024
1 parent d860282 commit a53f9a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/controllers/avo/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ class SearchController < ApplicationController
before_action :set_resource, only: :show

def show
render json: search_resources([resource])
render json: search_resources([resource], request:)
rescue => error
render_error _label: error.message
end

def process_results(results, request:)
results
end

private

def search_resources(resources)
def search_resources(resources, request: nil)
process_results search_results(resources, request:), request:
end

def search_results(resources, request: nil)
resources
.map do |resource|
# Apply authorization
Expand Down
9 changes: 9 additions & 0 deletions lib/avo/resources/resource_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ def get_resource_by_name(name)
get_resource name.singularize.camelize
end

# Returns the Avo resource by singular snake_cased name
#
# get_resource_by_name('z posts') => instance of Avo::Resources::ZPost
def get_resource_by_plural_name(name)
resources.find do |resource|
resource.plural_name == name
end
end

# Returns the Avo resource by singular snake_cased name
# From all the resources that use the same model_class, it will fetch the first one in alphabetical order
#
Expand Down

0 comments on commit a53f9a0

Please sign in to comment.