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

/api/app/controllers/spree/api/stock_locations_controller.rb

https://github.com/tomz/spree
Ruby | 50 lines | 43 code | 7 blank | 0 comment | 2 complexity | a128f14d0e174c21fb9c6925fdaf0dd8 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Api
  3. class StockLocationsController < Spree::Api::BaseController
  4. def index
  5. authorize! :read, StockLocation
  6. @stock_locations = StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  7. respond_with(@stock_locations)
  8. end
  9. def show
  10. respond_with(stock_location)
  11. end
  12. def create
  13. authorize! :create, StockLocation
  14. @stock_location = StockLocation.new(stock_location_params)
  15. if @stock_location.save
  16. respond_with(@stock_location, status: 201, default_template: :show)
  17. else
  18. invalid_resource!(@stock_location)
  19. end
  20. end
  21. def update
  22. authorize! :update, stock_location
  23. if stock_location.update_attributes(stock_location_params)
  24. respond_with(stock_location, status: 200, default_template: :show)
  25. else
  26. invalid_resource!(stock_location)
  27. end
  28. end
  29. def destroy
  30. authorize! :destroy, stock_location
  31. stock_location.destroy
  32. respond_with(stock_location, :status => 204)
  33. end
  34. private
  35. def stock_location
  36. @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:id])
  37. end
  38. def stock_location_params
  39. params.require(:stock_location).permit(permitted_stock_location_attributes)
  40. end
  41. end
  42. end
  43. end