paging done, needs some additional refactoring
This commit is contained in:
@@ -3,6 +3,10 @@ def get_querystring_hash()
|
||||
Rack::Utils.parse_nested_query(request.query_string)
|
||||
end
|
||||
|
||||
def add_total_count_header(total)
|
||||
response.headers['X-Total-Count'] = total
|
||||
end
|
||||
|
||||
# converts list of parameters to array of integers
|
||||
def mass_to_i(*id_strings)
|
||||
id_strings.map(&:to_i)
|
||||
|
||||
@@ -21,7 +21,7 @@ end
|
||||
|
||||
def filter_by_traits(items)
|
||||
get_querystring_hash.each do |k,v|
|
||||
items = items.where(["traits ->> '#{k}' = '#{v}'"])
|
||||
items = items.where(["traits ->> ? = ?", k, v])
|
||||
end
|
||||
items
|
||||
end
|
||||
@@ -54,9 +54,12 @@ get '/item/category/:category_id/offset/:offset/limit/:limit' do |category_id_s,
|
||||
input_invalid = offset_and_limit_invalid?(offset,limit) or category_id <= 0
|
||||
return [].to_json if input_invalid
|
||||
|
||||
all_in_cat = filter_by_traits(Item.all_in_category(category_id))
|
||||
items = Item.best_selling_in_category(category_id, offset,limit)
|
||||
items = filter_by_traits(items)
|
||||
|
||||
add_total_count_header(all_in_cat.count)
|
||||
|
||||
prepare_items_for_mass_display(items)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user