PageRenderTime 1276ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

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