PageRenderTime 1137ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/api/app/controllers/spree/api/stock_movements_controller.rb

https://github.com/tomz/spree
Ruby | 43 lines | 36 code | 7 blank | 0 comment | 1 complexity | 3d0110d85230bfd6c69fb262a49d085e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Api
  3. class StockMovementsController < Spree::Api::BaseController
  4. before_filter :stock_location, except: [:update, :destroy]
  5. def index
  6. authorize! :read, StockMovement
  7. @stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  8. respond_with(@stock_movements)
  9. end
  10. def show
  11. @stock_movement = scope.find(params[:id])
  12. respond_with(@stock_movement)
  13. end
  14. def create
  15. authorize! :create, StockMovement
  16. @stock_movement = scope.new(stock_movement_params)
  17. if @stock_movement.save
  18. respond_with(@stock_movement, status: 201, default_template: :show)
  19. else
  20. invalid_resource!(@stock_movement)
  21. end
  22. end
  23. private
  24. def stock_location
  25. render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
  26. @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
  27. end
  28. def scope
  29. @stock_location.stock_movements.accessible_by(current_ability, :read)
  30. end
  31. def stock_movement_params
  32. params.require(:stock_movement).permit(permitted_stock_movement_attributes)
  33. end
  34. end
  35. end
  36. end