spree_api 3.0.10 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +21 -22
  3. data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
  4. data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
  5. data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
  6. data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
  7. data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
  8. data/app/controllers/spree/api/v1/images_controller.rb +56 -0
  9. data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
  10. data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
  11. data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
  12. data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
  13. data/app/controllers/spree/api/v1/orders_controller.rb +137 -0
  14. data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
  15. data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
  16. data/app/controllers/spree/api/v1/products_controller.rb +126 -0
  17. data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
  18. data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
  19. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
  20. data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
  21. data/app/controllers/spree/api/v1/states_controller.rb +37 -0
  22. data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
  23. data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
  24. data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
  25. data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
  26. data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
  27. data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
  28. data/app/controllers/spree/api/v1/users_controller.rb +60 -0
  29. data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
  30. data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
  31. data/app/helpers/spree/api/api_helpers.rb +3 -2
  32. data/app/views/spree/api/{addresses → v1/addresses}/show.v1.rabl +0 -0
  33. data/app/views/spree/api/{adjustments → v1/adjustments}/show.v1.rabl +0 -0
  34. data/app/views/spree/api/{config → v1/config}/money.v1.rabl +0 -0
  35. data/app/views/spree/api/{config → v1/config}/show.v1.rabl +0 -0
  36. data/app/views/spree/api/{countries → v1/countries}/index.v1.rabl +0 -0
  37. data/app/views/spree/api/{countries → v1/countries}/show.v1.rabl +0 -0
  38. data/app/views/spree/api/{credit_cards → v1/credit_cards}/index.v1.rabl +1 -1
  39. data/app/views/spree/api/{credit_cards → v1/credit_cards}/show.v1.rabl +0 -0
  40. data/app/views/spree/api/{images → v1/images}/index.v1.rabl +1 -1
  41. data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
  42. data/app/views/spree/api/{images → v1/images}/show.v1.rabl +0 -0
  43. data/app/views/spree/api/{inventory_units → v1/inventory_units}/show.rabl +0 -0
  44. data/app/views/spree/api/{line_items → v1/line_items}/new.v1.rabl +0 -0
  45. data/app/views/spree/api/{line_items → v1/line_items}/show.v1.rabl +3 -3
  46. data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
  47. data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
  48. data/app/views/spree/api/{option_types → v1/option_types}/show.v1.rabl +0 -0
  49. data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
  50. data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
  51. data/app/views/spree/api/{option_values → v1/option_values}/show.v1.rabl +0 -0
  52. data/app/views/spree/api/{orders → v1/orders}/address.v1.rabl +0 -0
  53. data/app/views/spree/api/{orders → v1/orders}/canceled.v1.rabl +0 -0
  54. data/app/views/spree/api/{orders → v1/orders}/cart.v1.rabl +0 -0
  55. data/app/views/spree/api/{orders → v1/orders}/complete.v1.rabl +0 -0
  56. data/app/views/spree/api/{orders → v1/orders}/could_not_apply_coupon.v1.rabl +0 -0
  57. data/app/views/spree/api/{orders → v1/orders}/could_not_transition.v1.rabl +0 -0
  58. data/app/views/spree/api/{orders → v1/orders}/index.v1.rabl +1 -1
  59. data/app/views/spree/api/{orders → v1/orders}/invalid_shipping_method.v1.rabl +0 -0
  60. data/app/views/spree/api/{orders → v1/orders}/mine.v1.rabl +1 -1
  61. data/app/views/spree/api/{orders → v1/orders}/order.v1.rabl +1 -0
  62. data/app/views/spree/api/{orders → v1/orders}/payment.v1.rabl +0 -0
  63. data/app/views/spree/api/{orders → v1/orders}/show.v1.rabl +9 -9
  64. data/app/views/spree/api/{payments → v1/payments}/credit_over_limit.v1.rabl +0 -0
  65. data/app/views/spree/api/{payments → v1/payments}/index.v1.rabl +0 -0
  66. data/app/views/spree/api/{payments → v1/payments}/new.v1.rabl +0 -0
  67. data/app/views/spree/api/{payments → v1/payments}/show.v1.rabl +0 -0
  68. data/app/views/spree/api/{payments → v1/payments}/update_forbidden.v1.rabl +0 -0
  69. data/app/views/spree/api/{product_properties → v1/product_properties}/index.v1.rabl +0 -0
  70. data/app/views/spree/api/{product_properties → v1/product_properties}/new.v1.rabl +0 -0
  71. data/app/views/spree/api/{product_properties → v1/product_properties}/show.v1.rabl +0 -0
  72. data/app/views/spree/api/{products → v1/products}/index.v1.rabl +1 -1
  73. data/app/views/spree/api/{products → v1/products}/new.v1.rabl +0 -0
  74. data/app/views/spree/api/{products → v1/products}/product.v1.rabl +0 -0
  75. data/app/views/spree/api/{products → v1/products}/show.v1.rabl +3 -3
  76. data/app/views/spree/api/{promotions → v1/promotions}/handler.v1.rabl +0 -0
  77. data/app/views/spree/api/{promotions → v1/promotions}/show.v1.rabl +0 -0
  78. data/app/views/spree/api/{properties → v1/properties}/index.v1.rabl +0 -0
  79. data/app/views/spree/api/{properties → v1/properties}/new.v1.rabl +0 -0
  80. data/app/views/spree/api/{properties → v1/properties}/show.v1.rabl +0 -0
  81. data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/index.v1.rabl +0 -0
  82. data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/new.v1.rabl +0 -0
  83. data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/show.v1.rabl +0 -0
  84. data/app/views/spree/api/{shared → v1/shared}/stock_location_required.v1.rabl +0 -0
  85. data/app/views/spree/api/{shipments → v1/shipments}/big.v1.rabl +7 -7
  86. data/app/views/spree/api/{shipments → v1/shipments}/cannot_ready_shipment.v1.rabl +0 -0
  87. data/app/views/spree/api/{shipments → v1/shipments}/mine.v1.rabl +1 -1
  88. data/app/views/spree/api/{shipments → v1/shipments}/show.v1.rabl +3 -3
  89. data/app/views/spree/api/{shipments → v1/shipments}/small.v1.rabl +3 -3
  90. data/app/views/spree/api/{shipping_rates → v1/shipping_rates}/show.v1.rabl +0 -0
  91. data/app/views/spree/api/{states → v1/states}/index.v1.rabl +0 -0
  92. data/app/views/spree/api/{states → v1/states}/show.v1.rabl +0 -0
  93. data/app/views/spree/api/{stock_items → v1/stock_items}/index.v1.rabl +1 -1
  94. data/app/views/spree/api/{stock_items → v1/stock_items}/show.v1.rabl +1 -1
  95. data/app/views/spree/api/{stock_locations → v1/stock_locations}/index.v1.rabl +1 -1
  96. data/app/views/spree/api/{stock_locations → v1/stock_locations}/show.v1.rabl +0 -0
  97. data/app/views/spree/api/{stock_movements → v1/stock_movements}/index.v1.rabl +1 -1
  98. data/app/views/spree/api/{stock_movements → v1/stock_movements}/show.v1.rabl +1 -1
  99. data/app/views/spree/api/{stores → v1/stores}/index.v1.rabl +0 -0
  100. data/app/views/spree/api/{stores → v1/stores}/show.v1.rabl +0 -0
  101. data/app/views/spree/api/{taxonomies → v1/taxonomies}/index.v1.rabl +1 -1
  102. data/app/views/spree/api/{taxonomies → v1/taxonomies}/jstree.rabl +0 -0
  103. data/app/views/spree/api/{taxonomies → v1/taxonomies}/nested.v1.rabl +1 -1
  104. data/app/views/spree/api/{taxonomies → v1/taxonomies}/new.v1.rabl +0 -0
  105. data/app/views/spree/api/{taxonomies → v1/taxonomies}/show.v1.rabl +4 -4
  106. data/app/views/spree/api/{taxons → v1/taxons}/index.v1.rabl +1 -1
  107. data/app/views/spree/api/{taxons → v1/taxons}/jstree.rabl +0 -0
  108. data/app/views/spree/api/{taxons → v1/taxons}/new.v1.rabl +0 -0
  109. data/app/views/spree/api/{taxons → v1/taxons}/show.v1.rabl +0 -0
  110. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
  111. data/app/views/spree/api/{users → v1/users}/index.v1.rabl +1 -1
  112. data/app/views/spree/api/{users → v1/users}/new.v1.rabl +0 -0
  113. data/app/views/spree/api/{users → v1/users}/show.v1.rabl +2 -2
  114. data/app/views/spree/api/{variants → v1/variants}/big.v1.rabl +1 -1
  115. data/app/views/spree/api/{variants → v1/variants}/index.v1.rabl +1 -1
  116. data/app/views/spree/api/{variants → v1/variants}/new.v1.rabl +0 -0
  117. data/app/views/spree/api/{variants → v1/variants}/show.v1.rabl +1 -1
  118. data/app/views/spree/api/{variants → v1/variants}/small.v1.rabl +1 -1
  119. data/app/views/spree/api/{zones → v1/zones}/index.v1.rabl +1 -1
  120. data/app/views/spree/api/{zones → v1/zones}/show.v1.rabl +0 -0
  121. data/config/routes.rb +85 -88
  122. data/spec/controllers/spree/api/base_controller_spec.rb +14 -42
  123. data/spec/controllers/spree/api/{addresses_controller_spec.rb → v1/addresses_controller_spec.rb} +1 -1
  124. data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb} +51 -3
  125. data/spec/controllers/spree/api/{classifications_controller_spec.rb → v1/classifications_controller_spec.rb} +2 -2
  126. data/spec/controllers/spree/api/{countries_controller_spec.rb → v1/countries_controller_spec.rb} +1 -1
  127. data/spec/controllers/spree/api/{credit_cards_controller_spec.rb → v1/credit_cards_controller_spec.rb} +1 -1
  128. data/spec/controllers/spree/api/{images_controller_spec.rb → v1/images_controller_spec.rb} +23 -1
  129. data/spec/controllers/spree/api/{inventory_units_controller_spec.rb → v1/inventory_units_controller_spec.rb} +1 -1
  130. data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb} +2 -2
  131. data/spec/controllers/spree/api/{option_types_controller_spec.rb → v1/option_types_controller_spec.rb} +9 -3
  132. data/spec/controllers/spree/api/{option_values_controller_spec.rb → v1/option_values_controller_spec.rb} +8 -2
  133. data/spec/controllers/spree/api/{orders_controller_spec.rb → v1/orders_controller_spec.rb} +29 -8
  134. data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb} +2 -2
  135. data/spec/controllers/spree/api/{product_properties_controller_spec.rb → v1/product_properties_controller_spec.rb} +1 -1
  136. data/spec/controllers/spree/api/{products_controller_spec.rb → v1/products_controller_spec.rb} +5 -5
  137. data/spec/controllers/spree/api/{promotion_application_spec.rb → v1/promotion_application_spec.rb} +2 -2
  138. data/spec/controllers/spree/api/{promotions_controller_spec.rb → v1/promotions_controller_spec.rb} +1 -1
  139. data/spec/controllers/spree/api/{properties_controller_spec.rb → v1/properties_controller_spec.rb} +1 -1
  140. data/spec/controllers/spree/api/{return_authorizations_controller_spec.rb → v1/return_authorizations_controller_spec.rb} +1 -1
  141. data/spec/controllers/spree/api/{shipments_controller_spec.rb → v1/shipments_controller_spec.rb} +4 -4
  142. data/spec/controllers/spree/api/{states_controller_spec.rb → v1/states_controller_spec.rb} +14 -10
  143. data/spec/controllers/spree/api/{stock_items_controller_spec.rb → v1/stock_items_controller_spec.rb} +1 -1
  144. data/spec/controllers/spree/api/{stock_locations_controller_spec.rb → v1/stock_locations_controller_spec.rb} +1 -1
  145. data/spec/controllers/spree/api/{stock_movements_controller_spec.rb → v1/stock_movements_controller_spec.rb} +1 -1
  146. data/spec/controllers/spree/api/{stores_controller_spec.rb → v1/stores_controller_spec.rb} +1 -1
  147. data/spec/controllers/spree/api/{taxonomies_controller_spec.rb → v1/taxonomies_controller_spec.rb} +1 -1
  148. data/spec/controllers/spree/api/{taxons_controller_spec.rb → v1/taxons_controller_spec.rb} +1 -1
  149. data/spec/controllers/spree/api/{unauthenticated_products_controller_spec.rb → v1/unauthenticated_products_controller_spec.rb} +1 -1
  150. data/spec/controllers/spree/api/{users_controller_spec.rb → v1/users_controller_spec.rb} +1 -1
  151. data/spec/controllers/spree/api/{variants_controller_spec.rb → v1/variants_controller_spec.rb} +3 -3
  152. data/spec/controllers/spree/api/{zones_controller_spec.rb → v1/zones_controller_spec.rb} +7 -5
  153. data/spec/requests/rabl_cache_spec.rb +2 -2
  154. data/spec/requests/ransackable_attributes_spec.rb +6 -6
  155. data/spec/requests/version_spec.rb +19 -0
  156. data/spree_api.gemspec +1 -1
  157. metadata +188 -185
  158. data/CHANGELOG.md +0 -3
  159. data/app/controllers/spree/api/addresses_controller.rb +0 -43
  160. data/app/controllers/spree/api/checkouts_controller.rb +0 -98
  161. data/app/controllers/spree/api/classifications_controller.rb +0 -18
  162. data/app/controllers/spree/api/countries_controller.rb +0 -23
  163. data/app/controllers/spree/api/credit_cards_controller.rb +0 -25
  164. data/app/controllers/spree/api/images_controller.rb +0 -47
  165. data/app/controllers/spree/api/inventory_units_controller.rb +0 -52
  166. data/app/controllers/spree/api/line_items_controller.rb +0 -69
  167. data/app/controllers/spree/api/option_types_controller.rb +0 -49
  168. data/app/controllers/spree/api/option_values_controller.rb +0 -58
  169. data/app/controllers/spree/api/orders_controller.rb +0 -130
  170. data/app/controllers/spree/api/payments_controller.rb +0 -80
  171. data/app/controllers/spree/api/product_properties_controller.rb +0 -72
  172. data/app/controllers/spree/api/products_controller.rb +0 -124
  173. data/app/controllers/spree/api/promotions_controller.rb +0 -26
  174. data/app/controllers/spree/api/properties_controller.rb +0 -70
  175. data/app/controllers/spree/api/return_authorizations_controller.rb +0 -69
  176. data/app/controllers/spree/api/shipments_controller.rb +0 -149
  177. data/app/controllers/spree/api/states_controller.rb +0 -38
  178. data/app/controllers/spree/api/stock_items_controller.rb +0 -75
  179. data/app/controllers/spree/api/stock_locations_controller.rb +0 -50
  180. data/app/controllers/spree/api/stock_movements_controller.rb +0 -43
  181. data/app/controllers/spree/api/stores_controller.rb +0 -55
  182. data/app/controllers/spree/api/taxonomies_controller.rb +0 -64
  183. data/app/controllers/spree/api/taxons_controller.rb +0 -93
  184. data/app/controllers/spree/api/users_controller.rb +0 -56
  185. data/app/controllers/spree/api/variants_controller.rb +0 -73
  186. data/app/controllers/spree/api/zones_controller.rb +0 -49
  187. data/app/models/spree/option_value_decorator.rb +0 -9
  188. data/app/views/spree/api/option_types/index.v1.rabl +0 -3
  189. data/app/views/spree/api/option_values/index.v1.rabl +0 -3
  190. data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
@@ -0,0 +1,37 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class StatesController < Spree::Api::BaseController
5
+ skip_before_action :authenticate_user
6
+
7
+ def index
8
+ @states = scope.ransack(params[:q]).result.includes(:country)
9
+
10
+ if params[:page] || params[:per_page]
11
+ @states = @states.page(params[:page]).per(params[:per_page])
12
+ end
13
+
14
+ state = @states.last
15
+ if stale?(state)
16
+ respond_with(@states)
17
+ end
18
+ end
19
+
20
+ def show
21
+ @state = scope.find(params[:id])
22
+ respond_with(@state)
23
+ end
24
+
25
+ private
26
+ def scope
27
+ if params[:country_id]
28
+ @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
29
+ return @country.states.accessible_by(current_ability, :read).order('name ASC')
30
+ else
31
+ return State.accessible_by(current_ability, :read).order('name ASC')
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,77 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class StockItemsController < Spree::Api::BaseController
5
+ before_action :stock_location, except: [:update, :destroy]
6
+
7
+ def index
8
+ @stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
9
+ respond_with(@stock_items)
10
+ end
11
+
12
+ def show
13
+ @stock_item = scope.find(params[:id])
14
+ respond_with(@stock_item)
15
+ end
16
+
17
+ def create
18
+ authorize! :create, StockItem
19
+
20
+ count_on_hand = 0
21
+ if params[:stock_item].has_key?(:count_on_hand)
22
+ count_on_hand = params[:stock_item][:count_on_hand].to_i
23
+ end
24
+
25
+ @stock_item = scope.new(stock_item_params)
26
+ if @stock_item.save
27
+ @stock_item.adjust_count_on_hand(count_on_hand)
28
+ respond_with(@stock_item, status: 201, default_template: :show)
29
+ else
30
+ invalid_resource!(@stock_item)
31
+ end
32
+ end
33
+
34
+ def update
35
+ @stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
36
+
37
+ count_on_hand = 0
38
+ if params[:stock_item].has_key?(:count_on_hand)
39
+ count_on_hand = params[:stock_item][:count_on_hand].to_i
40
+ params[:stock_item].delete(:count_on_hand)
41
+ end
42
+
43
+ updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)
44
+ : @stock_item.adjust_count_on_hand(count_on_hand)
45
+
46
+ if updated
47
+ respond_with(@stock_item, status: 200, default_template: :show)
48
+ else
49
+ invalid_resource!(@stock_item)
50
+ end
51
+ end
52
+
53
+ def destroy
54
+ @stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
55
+ @stock_item.destroy
56
+ respond_with(@stock_item, status: 204)
57
+ end
58
+
59
+ private
60
+
61
+ def stock_location
62
+ render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
63
+ @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
64
+ end
65
+
66
+ def scope
67
+ includes = {:variant => [{ :option_values => :option_type }, :product] }
68
+ @stock_location.stock_items.accessible_by(current_ability, :read).includes(includes)
69
+ end
70
+
71
+ def stock_item_params
72
+ params.require(:stock_item).permit(permitted_stock_item_attributes)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,52 @@
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
+
11
+ def show
12
+ respond_with(stock_location)
13
+ end
14
+
15
+ def create
16
+ authorize! :create, StockLocation
17
+ @stock_location = StockLocation.new(stock_location_params)
18
+ if @stock_location.save
19
+ respond_with(@stock_location, status: 201, default_template: :show)
20
+ else
21
+ invalid_resource!(@stock_location)
22
+ end
23
+ end
24
+
25
+ def update
26
+ authorize! :update, stock_location
27
+ if stock_location.update_attributes(stock_location_params)
28
+ respond_with(stock_location, status: 200, default_template: :show)
29
+ else
30
+ invalid_resource!(stock_location)
31
+ end
32
+ end
33
+
34
+ def destroy
35
+ authorize! :destroy, stock_location
36
+ stock_location.destroy
37
+ respond_with(stock_location, :status => 204)
38
+ end
39
+
40
+ private
41
+
42
+ def stock_location
43
+ @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:id])
44
+ end
45
+
46
+ def stock_location_params
47
+ params.require(:stock_location).permit(permitted_stock_location_attributes)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class StockMovementsController < Spree::Api::BaseController
5
+ before_action :stock_location, except: [:update, :destroy]
6
+
7
+ def index
8
+ authorize! :read, StockMovement
9
+ @stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
10
+ respond_with(@stock_movements)
11
+ end
12
+
13
+ def show
14
+ @stock_movement = scope.find(params[:id])
15
+ respond_with(@stock_movement)
16
+ end
17
+
18
+ def create
19
+ authorize! :create, StockMovement
20
+ @stock_movement = scope.new(stock_movement_params)
21
+ if @stock_movement.save
22
+ respond_with(@stock_movement, status: 201, default_template: :show)
23
+ else
24
+ invalid_resource!(@stock_movement)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def stock_location
31
+ render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
32
+ @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
33
+ end
34
+
35
+ def scope
36
+ @stock_location.stock_movements.accessible_by(current_ability, :read)
37
+ end
38
+
39
+ def stock_movement_params
40
+ params.require(:stock_movement).permit(permitted_stock_movement_attributes)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,57 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class StoresController < Spree::Api::BaseController
5
+
6
+ before_action :get_store, except: [:index, :create]
7
+
8
+ def index
9
+ authorize! :read, Store
10
+ @stores = Store.accessible_by(current_ability, :read).all
11
+ respond_with(@stores)
12
+ end
13
+
14
+ def create
15
+ authorize! :create, Store
16
+ @store = Store.new(store_params)
17
+ @store.code = params[:store][:code]
18
+ if @store.save
19
+ respond_with(@store, status: 201, default_template: :show)
20
+ else
21
+ invalid_resource!(@store)
22
+ end
23
+ end
24
+
25
+ def update
26
+ authorize! :update, @store
27
+ if @store.update_attributes(store_params)
28
+ respond_with(@store, status: 200, default_template: :show)
29
+ else
30
+ invalid_resource!(@store)
31
+ end
32
+ end
33
+
34
+ def show
35
+ authorize! :read, @store
36
+ respond_with(@store)
37
+ end
38
+
39
+ def destroy
40
+ authorize! :destroy, @store
41
+ @store.destroy
42
+ respond_with(@store, status: 204)
43
+ end
44
+
45
+ private
46
+
47
+ def get_store
48
+ @store = Store.find(params[:id])
49
+ end
50
+
51
+ def store_params
52
+ params.require(:store).permit(permitted_store_attributes)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,66 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class TaxonomiesController < Spree::Api::BaseController
5
+
6
+ def index
7
+ respond_with(taxonomies)
8
+ end
9
+
10
+ def show
11
+ respond_with(taxonomy)
12
+ end
13
+
14
+ # Because JSTree wants parameters in a *slightly* different format
15
+ def jstree
16
+ show
17
+ end
18
+
19
+ def create
20
+ authorize! :create, Taxonomy
21
+ @taxonomy = Taxonomy.new(taxonomy_params)
22
+ if @taxonomy.save
23
+ respond_with(@taxonomy, :status => 201, :default_template => :show)
24
+ else
25
+ invalid_resource!(@taxonomy)
26
+ end
27
+ end
28
+
29
+ def update
30
+ authorize! :update, taxonomy
31
+ if taxonomy.update_attributes(taxonomy_params)
32
+ respond_with(taxonomy, :status => 200, :default_template => :show)
33
+ else
34
+ invalid_resource!(taxonomy)
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ authorize! :destroy, taxonomy
40
+ taxonomy.destroy
41
+ respond_with(taxonomy, :status => 204)
42
+ end
43
+
44
+ private
45
+
46
+ def taxonomies
47
+ @taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
48
+ ransack(params[:q]).result.
49
+ page(params[:page]).per(params[:per_page])
50
+ end
51
+
52
+ def taxonomy
53
+ @taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
54
+ end
55
+
56
+ def taxonomy_params
57
+ if params[:taxonomy] && !params[:taxonomy].empty?
58
+ params.require(:taxonomy).permit(permitted_taxonomy_attributes)
59
+ else
60
+ {}
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,95 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class TaxonsController < Spree::Api::BaseController
5
+ def index
6
+ if taxonomy
7
+ @taxons = taxonomy.root.children
8
+ else
9
+ if params[:ids]
10
+ @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
11
+ else
12
+ @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
13
+ end
14
+ end
15
+
16
+ @taxons = @taxons.page(params[:page]).per(params[:per_page])
17
+ respond_with(@taxons)
18
+ end
19
+
20
+ def show
21
+ @taxon = taxon
22
+ respond_with(@taxon)
23
+ end
24
+
25
+ def jstree
26
+ show
27
+ end
28
+
29
+ def create
30
+ authorize! :create, Taxon
31
+ @taxon = Spree::Taxon.new(taxon_params)
32
+ @taxon.taxonomy_id = params[:taxonomy_id]
33
+ taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
34
+
35
+ if taxonomy.nil?
36
+ @taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
37
+ invalid_resource!(@taxon) and return
38
+ end
39
+
40
+ @taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
41
+
42
+ if @taxon.save
43
+ respond_with(@taxon, status: 201, default_template: :show)
44
+ else
45
+ invalid_resource!(@taxon)
46
+ end
47
+ end
48
+
49
+ def update
50
+ authorize! :update, taxon
51
+ if taxon.update_attributes(taxon_params)
52
+ respond_with(taxon, status: 200, default_template: :show)
53
+ else
54
+ invalid_resource!(taxon)
55
+ end
56
+ end
57
+
58
+ def destroy
59
+ authorize! :destroy, taxon
60
+ taxon.destroy
61
+ respond_with(taxon, status: 204)
62
+ end
63
+
64
+ def products
65
+ # Returns the products sorted by their position with the classification
66
+ # Products#index does not do the sorting.
67
+ taxon = Spree::Taxon.find(params[:id])
68
+ @products = taxon.products.ransack(params[:q]).result
69
+ @products = @products.page(params[:page]).per(params[:per_page] || 500)
70
+ render "spree/api/v1/products/index"
71
+ end
72
+
73
+ private
74
+
75
+ def taxonomy
76
+ if params[:taxonomy_id].present?
77
+ @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
78
+ end
79
+ end
80
+
81
+ def taxon
82
+ @taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
83
+ end
84
+
85
+ def taxon_params
86
+ if params[:taxon] && !params[:taxon].empty?
87
+ params.require(:taxon).permit(permitted_taxon_attributes)
88
+ else
89
+ {}
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,60 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class UsersController < Spree::Api::BaseController
5
+
6
+ rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
7
+
8
+ def index
9
+ @users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
10
+ respond_with(@users)
11
+ end
12
+
13
+ def show
14
+ respond_with(user)
15
+ end
16
+
17
+ def new
18
+ end
19
+
20
+ def create
21
+ authorize! :create, Spree.user_class
22
+ @user = Spree.user_class.new(user_params)
23
+ if @user.save
24
+ respond_with(@user, :status => 201, :default_template => :show)
25
+ else
26
+ invalid_resource!(@user)
27
+ end
28
+ end
29
+
30
+ def update
31
+ authorize! :update, user
32
+ if user.update_attributes(user_params)
33
+ respond_with(user, :status => 200, :default_template => :show)
34
+ else
35
+ invalid_resource!(user)
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ authorize! :destroy, user
41
+ user.destroy
42
+ respond_with(user, :status => 204)
43
+ end
44
+
45
+ private
46
+
47
+ def user
48
+ @user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
49
+ end
50
+
51
+ def user_params
52
+ params.require(:user).permit(permitted_user_attributes |
53
+ [bill_address_attributes: permitted_address_attributes,
54
+ ship_address_attributes: permitted_address_attributes])
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end