#slice :params in controller and rename to :args in service context

This commit is contained in:
Matt-Yorkley
2019-10-07 17:07:43 +01:00
parent 06c896b93b
commit 542c1bf684
2 changed files with 7 additions and 7 deletions

View File

@@ -10,7 +10,7 @@ module Api
distributor,
order_cycle,
customer,
params
params.slice(:q, :page, :per_page)
).products_json
render json: products

View File

@@ -5,11 +5,11 @@ class ProductsRenderer
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 10
def initialize(distributor, order_cycle, customer, params = {})
def initialize(distributor, order_cycle, customer, args = {})
@distributor = distributor
@order_cycle = order_cycle
@customer = customer
@params = params
@args = args
end
def products_json
@@ -26,7 +26,7 @@ class ProductsRenderer
private
attr_reader :order_cycle, :distributor, :customer, :params
attr_reader :order_cycle, :distributor, :customer, :args
def products
return unless order_cycle
@@ -49,10 +49,10 @@ class ProductsRenderer
def filter_and_paginate(query)
query.
ransack(params[:q]).
ransack(args[:q]).
result.
page(params[:page] || DEFAULT_PAGE).
per(params[:per_page] || DEFAULT_PER_PAGE)
page(args[:page] || DEFAULT_PAGE).
per(args[:per_page] || DEFAULT_PER_PAGE)
end
def distributed_products