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

https://github.com/solidusio/solidus · Ruby · 60 lines · 48 code · 11 blank · 1 comment · 2 complexity · bd7bf3b3a9ebedfcd6762c08707a9870 MD5 · raw file

  1. # frozen_string_literal: true
  2. module Spree
  3. module Api
  4. class StockLocationsController < Spree::Api::BaseController
  5. def index
  6. authorize! :index, StockLocation
  7. @stock_locations = StockLocation.
  8. accessible_by(current_ability).
  9. order('name ASC').
  10. ransack(params[:q]).
  11. result
  12. @stock_locations = paginate(@stock_locations)
  13. respond_with(@stock_locations)
  14. end
  15. def show
  16. respond_with(stock_location)
  17. end
  18. def create
  19. authorize! :create, StockLocation
  20. @stock_location = Spree::StockLocation.new(stock_location_params)
  21. if @stock_location.save
  22. respond_with(@stock_location, status: 201, default_template: :show)
  23. else
  24. invalid_resource!(@stock_location)
  25. end
  26. end
  27. def update
  28. authorize! :update, stock_location
  29. if stock_location.update(stock_location_params)
  30. respond_with(stock_location, status: 200, default_template: :show)
  31. else
  32. invalid_resource!(stock_location)
  33. end
  34. end
  35. def destroy
  36. authorize! :destroy, stock_location
  37. stock_location.destroy
  38. respond_with(stock_location, status: 204)
  39. end
  40. private
  41. def stock_location
  42. @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :show).find(params[:id])
  43. end
  44. def stock_location_params
  45. params.require(:stock_location).permit(permitted_stock_location_attributes)
  46. end
  47. end
  48. end
  49. end