@@ -4,7 +4,7 @@ class InventoryItemsController < ApplicationController
44 # Show a single inventory_item
55 # List all inventory_items
66 # Example:
7- # ` curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items/1.json'
7+ # ` curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items/1.json?representation=full '
88 def show
99 Rails . logger . debug "Inventory Item with ID #{ @item . id } is #{ @item . inspect } "
1010
@@ -17,9 +17,10 @@ def show
1717
1818 # List all inventory_items
1919 # Example:
20- # ` curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items.json'
20+ # ` curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items.json?representation=full&limit=15&offset=30 '
2121 def index
22- all_items = InventoryItem . all
22+ lim , off = sanitized_limit_and_offset
23+ all_items = InventoryItem . all . limit ( lim ) . offset ( off )
2324 return json_response ( [ ] ) unless newest_item = all_items . sort_by ( &:updated_at ) . last
2425 Rails . logger . info "newest_item is #{ newest_item . inspect } "
2526 render_if_stale ( all_items , last_modified : newest_item . updated_at . utc , etag : newest_item ) do |item_presenters |
@@ -70,9 +71,10 @@ def destroy
7071
7172 # Find inventory items filtered by a given city ID
7273 # Example:
73- # `curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items/in_city/1.json'`
74+ # `curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items/in_city/1.json?representation=full&limit=15&offset=30 '`
7475 def in_city
75- return json_response ( [ ] ) if ( city_items = InventoryItem . where ( params . slice ( :city_id ) ) ) . blank?
76+ lim , off = sanitized_limit_and_offset
77+ return json_response ( [ ] ) if ( city_items = InventoryItem . where ( params . slice ( :city_id ) ) . limit ( lim ) . offset ( off ) ) . blank?
7678 newest_item = city_items . sort_by ( &:updated_at ) . last
7779 Rails . logger . info "newest_item is #{ newest_item . inspect } "
7880 render_if_stale ( city_items , last_modified : newest_item . updated_at . utc , etag : newest_item ) do |item_presenters |
@@ -84,12 +86,13 @@ def in_city
8486
8587 # Find inventory items in a given city ID, or near that city within a given number of miles (default: 15 miles)
8688 # Example:
87- # `curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items/near_city/1.json?within=20'`
89+ # `curl -v -H "Content-type: application/json" 'http://localhost:3000/api/v1/inventory_items/near_city/1.json?within=20&representation=full&limit=15&offset=30 '`
8890 def near_city
91+ lim , off = sanitized_limit_and_offset
8992 nearby_city_ids = RemoteCity . find_nearby_city_id ( params [ :city_id ] , params . fetch ( :within , 15 ) ) . map ( &:id )
9093 nearby_city_ids << params [ :city_id ] . to_i if params [ :city_id ] . to_i
9194 Rails . logger . info "nearby city IDs (including the requested city itself): #{ nearby_city_ids } "
92- city_items = InventoryItem . where ( city_id : nearby_city_ids )
95+ city_items = InventoryItem . where ( city_id : nearby_city_ids ) . limit ( lim ) . offset ( off )
9396 return json_response ( [ ] ) if city_items . blank?
9497 newest_item = city_items . sort_by ( &:updated_at ) . last
9598 Rails . logger . info "newest_item is #{ newest_item . inspect } "
0 commit comments