diff options
Diffstat (limited to 'app/controllers/api')
-rw-r--r-- | app/controllers/api/products_controller.rb | 9 |
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 |