summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-16 13:02:26 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-16 13:02:26 -0600
commit62ebfcb0901002c1377d5677ed1a0d062ab94ff0 (patch)
treee6eb92f5d1fe2dc618e02f577c43ef0b4d256f79 /app/controllers/api
parentf158d350f10ae6850c7ee168f0345197c3265d5c (diff)
Añade búsqueda de productos
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/products_controller.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb
index 9ebdac8..59019d0 100644
--- a/app/controllers/api/products_controller.rb
+++ b/app/controllers/api/products_controller.rb
@@ -10,7 +10,8 @@ module Api
end
def index
- @products = Product.all
+ @search = Searches::ProductSearch.new(scope, search_params)
+ @products = @search.call
render json: serialized_collection.serializable_hash, status: :ok
end
@@ -59,7 +60,7 @@ module Api
end
def serialized_collection
- ProductSerializer.new(scope.page(params[:page]))
+ ProductSerializer.new(@products.page(params[:page]))
end
def permitted_params
@@ -72,5 +73,9 @@ module Api
public_id = SecureRandom.hex(12) while Product.exists?(public_id:)
permitted_params.merge(categories:, public_id:)
end
+
+ def search_params
+ params.permit(:name, :company, :category, :quantity, :bulk_price, :price)
+ end
end
end