Class: Spree::Api::V1::ReservedStockItemsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Api::V1::ReservedStockItemsController
- Defined in:
- app/controllers/spree/api/v1/reserved_stock_items_controller.rb
Overview
API Controller for reserving, restocking and expiring stock
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/spree/api/v1/reserved_stock_items_controller.rb', line 8 def index @reserved_stock_items = scope.all.page(params[:page]).per(params[:per_page]) respond_with(@reserved_stock_items) end |
#reserve ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/spree/api/v1/reserved_stock_items_controller.rb', line 13 def reserve render_reserve_param_errors(params); return if performed? @reserved_stock_item = Spree::Stock::Reserver.new.reserve( variant, original_stock_location, user, params[:quantity], params[:expires_at] ) respond_with(@reserved_stock_item, status: :created, default_template: :show) rescue => e # TODO: Appropriate error if @reserved_stock_item not returned invalid_resource!(@reserved_stock_item) end |
#restock ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/controllers/spree/api/v1/reserved_stock_items_controller.rb', line 28 def restock @reserved_stock_item = Spree::Stock::Reserver.new.restock( variant, user, params[:quantity] ) respond_with(@reserved_stock_item, status: :created, default_template: :show) rescue => e invalid_resource!(@reserved_stock_item) end |
#restock_expired ⇒ Object
37 38 39 40 41 42 |
# File 'app/controllers/spree/api/v1/reserved_stock_items_controller.rb', line 37 def restock_expired Spree::Stock::Reserver.new.restock_expired head 204 # return success with no body rescue => e # TODO: error message end |