From 62ebfcb0901002c1377d5677ed1a0d062ab94ff0 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 16 Apr 2023 13:02:26 -0600 Subject: Añade búsqueda de productos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/products_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/controllers/api/products_controller.rb') 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 -- cgit v1.2.3