spree_api 4.4.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +10 -8
  3. data/app/controllers/spree/api/v2/platform/orders_controller.rb +1 -1
  4. data/app/controllers/spree/api/v2/platform/products_controller.rb +5 -1
  5. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +1 -1
  6. data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +5 -1
  7. data/app/controllers/spree/api/v2/storefront/stores_controller.rb +4 -0
  8. data/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb +35 -0
  9. data/app/models/concerns/spree/webhooks/has_webhooks.rb +31 -7
  10. data/app/models/spree/api/webhooks/product_decorator.rb +21 -2
  11. data/app/models/spree/webhooks/subscriber.rb +4 -0
  12. data/app/serializers/spree/api/v2/platform/cms_section_image_one_serializer.rb +9 -0
  13. data/app/serializers/spree/api/v2/platform/cms_section_image_three_serializer.rb +9 -0
  14. data/app/serializers/spree/api/v2/platform/cms_section_image_two_serializer.rb +9 -0
  15. data/app/serializers/spree/api/v2/platform/hero_image_serializer.rb +10 -0
  16. data/app/serializers/spree/api/v2/platform/image_gallery_serializer.rb +10 -0
  17. data/app/serializers/spree/api/v2/platform/side_by_side_image_serializer.rb +10 -0
  18. data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -0
  19. data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
  20. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +3 -3
  21. data/app/serializers/spree/v2/storefront/order_serializer.rb +9 -0
  22. data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
  23. data/app/serializers/spree/v2/storefront/product_serializer.rb +1 -1
  24. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -0
  25. data/app/serializers/spree/v2/storefront/store_serializer.rb +5 -10
  26. data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
  27. data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
  28. data/app/services/spree/webhooks/subscribers/queue_requests.rb +8 -2
  29. data/config/routes.rb +1 -120
  30. data/docs/v2/platform/index.yaml +1597 -998
  31. data/docs/v2/storefront/index.yaml +357 -33
  32. data/lib/spree/api/configuration.rb +11 -0
  33. data/lib/spree/api/dependencies.rb +165 -0
  34. data/lib/spree/api/engine.rb +5 -16
  35. data/lib/spree/api/testing_support/v2/platform_contexts.rb +0 -1
  36. data/lib/spree/api.rb +0 -4
  37. data/lib/spree_api.rb +0 -1
  38. data/spree_api.gemspec +0 -2
  39. metadata +16 -177
  40. data/app/controllers/spree/api/base_controller.rb +0 -171
  41. data/app/controllers/spree/api/v1/addresses_controller.rb +0 -46
  42. data/app/controllers/spree/api/v1/checkouts_controller.rb +0 -106
  43. data/app/controllers/spree/api/v1/classifications_controller.rb +0 -21
  44. data/app/controllers/spree/api/v1/countries_controller.rb +0 -22
  45. data/app/controllers/spree/api/v1/credit_cards_controller.rb +0 -26
  46. data/app/controllers/spree/api/v1/customer_returns_controller.rb +0 -25
  47. data/app/controllers/spree/api/v1/images_controller.rb +0 -58
  48. data/app/controllers/spree/api/v1/inventory_units_controller.rb +0 -54
  49. data/app/controllers/spree/api/v1/line_items_controller.rb +0 -70
  50. data/app/controllers/spree/api/v1/option_types_controller.rb +0 -60
  51. data/app/controllers/spree/api/v1/option_values_controller.rb +0 -62
  52. data/app/controllers/spree/api/v1/orders_controller.rb +0 -160
  53. data/app/controllers/spree/api/v1/payments_controller.rb +0 -82
  54. data/app/controllers/spree/api/v1/product_properties_controller.rb +0 -73
  55. data/app/controllers/spree/api/v1/products_controller.rb +0 -131
  56. data/app/controllers/spree/api/v1/promotions_controller.rb +0 -30
  57. data/app/controllers/spree/api/v1/properties_controller.rb +0 -70
  58. data/app/controllers/spree/api/v1/reimbursements_controller.rb +0 -25
  59. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -70
  60. data/app/controllers/spree/api/v1/shipments_controller.rb +0 -196
  61. data/app/controllers/spree/api/v1/states_controller.rb +0 -36
  62. data/app/controllers/spree/api/v1/stock_items_controller.rb +0 -82
  63. data/app/controllers/spree/api/v1/stock_locations_controller.rb +0 -53
  64. data/app/controllers/spree/api/v1/stock_movements_controller.rb +0 -45
  65. data/app/controllers/spree/api/v1/stores_controller.rb +0 -56
  66. data/app/controllers/spree/api/v1/taxonomies_controller.rb +0 -67
  67. data/app/controllers/spree/api/v1/taxons_controller.rb +0 -100
  68. data/app/controllers/spree/api/v1/users_controller.rb +0 -97
  69. data/app/controllers/spree/api/v1/variants_controller.rb +0 -81
  70. data/app/controllers/spree/api/v1/zones_controller.rb +0 -55
  71. data/app/helpers/spree/api/api_helpers.rb +0 -190
  72. data/app/models/spree/api_configuration.rb +0 -10
  73. data/app/views/spree/api/errors/gateway_error.rabl +0 -2
  74. data/app/views/spree/api/errors/invalid_api_key.rabl +0 -2
  75. data/app/views/spree/api/errors/invalid_resource.rabl +0 -3
  76. data/app/views/spree/api/errors/must_specify_api_key.rabl +0 -2
  77. data/app/views/spree/api/errors/not_found.rabl +0 -2
  78. data/app/views/spree/api/errors/unauthorized.rabl +0 -2
  79. data/app/views/spree/api/v1/addresses/show.rabl +0 -10
  80. data/app/views/spree/api/v1/adjustments/show.rabl +0 -4
  81. data/app/views/spree/api/v1/countries/index.rabl +0 -7
  82. data/app/views/spree/api/v1/countries/show.rabl +0 -5
  83. data/app/views/spree/api/v1/credit_cards/index.rabl +0 -7
  84. data/app/views/spree/api/v1/credit_cards/show.rabl +0 -3
  85. data/app/views/spree/api/v1/customer_returns/index.rabl +0 -7
  86. data/app/views/spree/api/v1/images/index.rabl +0 -4
  87. data/app/views/spree/api/v1/images/new.rabl +0 -3
  88. data/app/views/spree/api/v1/images/show.rabl +0 -6
  89. data/app/views/spree/api/v1/inventory_units/show.rabl +0 -2
  90. data/app/views/spree/api/v1/line_items/new.rabl +0 -3
  91. data/app/views/spree/api/v1/line_items/show.rabl +0 -14
  92. data/app/views/spree/api/v1/option_types/index.rabl +0 -3
  93. data/app/views/spree/api/v1/option_types/new.rabl +0 -3
  94. data/app/views/spree/api/v1/option_types/show.rabl +0 -5
  95. data/app/views/spree/api/v1/option_values/index.rabl +0 -3
  96. data/app/views/spree/api/v1/option_values/new.rabl +0 -3
  97. data/app/views/spree/api/v1/option_values/show.rabl +0 -2
  98. data/app/views/spree/api/v1/orders/address.rabl +0 -0
  99. data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
  100. data/app/views/spree/api/v1/orders/cart.rabl +0 -0
  101. data/app/views/spree/api/v1/orders/complete.rabl +0 -0
  102. data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +0 -2
  103. data/app/views/spree/api/v1/orders/could_not_transition.rabl +0 -3
  104. data/app/views/spree/api/v1/orders/index.rabl +0 -7
  105. data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +0 -2
  106. data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +0 -2
  107. data/app/views/spree/api/v1/orders/mine.rabl +0 -9
  108. data/app/views/spree/api/v1/orders/order.rabl +0 -10
  109. data/app/views/spree/api/v1/orders/payment.rabl +0 -3
  110. data/app/views/spree/api/v1/orders/show.rabl +0 -51
  111. data/app/views/spree/api/v1/payments/credit_over_limit.rabl +0 -2
  112. data/app/views/spree/api/v1/payments/index.rabl +0 -7
  113. data/app/views/spree/api/v1/payments/new.rabl +0 -5
  114. data/app/views/spree/api/v1/payments/show.rabl +0 -2
  115. data/app/views/spree/api/v1/payments/update_forbidden.rabl +0 -2
  116. data/app/views/spree/api/v1/product_properties/index.rabl +0 -7
  117. data/app/views/spree/api/v1/product_properties/new.rabl +0 -2
  118. data/app/views/spree/api/v1/product_properties/show.rabl +0 -2
  119. data/app/views/spree/api/v1/products/index.rabl +0 -9
  120. data/app/views/spree/api/v1/products/new.rabl +0 -3
  121. data/app/views/spree/api/v1/products/product.rabl +0 -1
  122. data/app/views/spree/api/v1/products/show.rabl +0 -36
  123. data/app/views/spree/api/v1/promotions/handler.rabl +0 -5
  124. data/app/views/spree/api/v1/promotions/show.rabl +0 -2
  125. data/app/views/spree/api/v1/properties/index.rabl +0 -7
  126. data/app/views/spree/api/v1/properties/new.rabl +0 -2
  127. data/app/views/spree/api/v1/properties/show.rabl +0 -2
  128. data/app/views/spree/api/v1/reimbursements/index.rabl +0 -7
  129. data/app/views/spree/api/v1/return_authorizations/index.rabl +0 -7
  130. data/app/views/spree/api/v1/return_authorizations/new.rabl +0 -3
  131. data/app/views/spree/api/v1/return_authorizations/show.rabl +0 -2
  132. data/app/views/spree/api/v1/shared/stock_location_required.rabl +0 -2
  133. data/app/views/spree/api/v1/shipments/big.rabl +0 -48
  134. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +0 -2
  135. data/app/views/spree/api/v1/shipments/mine.rabl +0 -9
  136. data/app/views/spree/api/v1/shipments/show.rabl +0 -32
  137. data/app/views/spree/api/v1/shipments/small.rabl +0 -37
  138. data/app/views/spree/api/v1/shipping_rates/show.rabl +0 -2
  139. data/app/views/spree/api/v1/states/index.rabl +0 -12
  140. data/app/views/spree/api/v1/states/show.rabl +0 -2
  141. data/app/views/spree/api/v1/stock_items/index.rabl +0 -7
  142. data/app/views/spree/api/v1/stock_items/show.rabl +0 -5
  143. data/app/views/spree/api/v1/stock_locations/index.rabl +0 -7
  144. data/app/views/spree/api/v1/stock_locations/show.rabl +0 -8
  145. data/app/views/spree/api/v1/stock_movements/index.rabl +0 -7
  146. data/app/views/spree/api/v1/stock_movements/show.rabl +0 -5
  147. data/app/views/spree/api/v1/stores/index.rabl +0 -4
  148. data/app/views/spree/api/v1/stores/show.rabl +0 -2
  149. data/app/views/spree/api/v1/tags/index.rabl +0 -9
  150. data/app/views/spree/api/v1/taxonomies/index.rabl +0 -7
  151. data/app/views/spree/api/v1/taxonomies/jstree.rabl +0 -7
  152. data/app/views/spree/api/v1/taxonomies/nested.rabl +0 -11
  153. data/app/views/spree/api/v1/taxonomies/new.rabl +0 -3
  154. data/app/views/spree/api/v1/taxonomies/show.rabl +0 -15
  155. data/app/views/spree/api/v1/taxons/index.rabl +0 -10
  156. data/app/views/spree/api/v1/taxons/jstree.rabl +0 -7
  157. data/app/views/spree/api/v1/taxons/new.rabl +0 -3
  158. data/app/views/spree/api/v1/taxons/show.rabl +0 -6
  159. data/app/views/spree/api/v1/taxons/taxons.rabl +0 -5
  160. data/app/views/spree/api/v1/users/index.rabl +0 -7
  161. data/app/views/spree/api/v1/users/new.rabl +0 -3
  162. data/app/views/spree/api/v1/users/show.rabl +0 -11
  163. data/app/views/spree/api/v1/variants/big.rabl +0 -14
  164. data/app/views/spree/api/v1/variants/index.rabl +0 -9
  165. data/app/views/spree/api/v1/variants/new.rabl +0 -2
  166. data/app/views/spree/api/v1/variants/show.rabl +0 -3
  167. data/app/views/spree/api/v1/variants/small.rabl +0 -18
  168. data/app/views/spree/api/v1/zones/index.rabl +0 -7
  169. data/app/views/spree/api/v1/zones/show.rabl +0 -6
  170. data/config/initializers/rabl.rb +0 -9
  171. data/lib/spree/api/api_dependencies.rb +0 -163
  172. data/lib/spree/api/controller_setup.rb +0 -19
  173. data/lib/spree/api/responders/rabl_template.rb +0 -28
  174. data/lib/spree/api/responders.rb +0 -11
  175. data/lib/spree/api/testing_support/helpers.rb +0 -44
  176. data/lib/spree/api/testing_support/setup.rb +0 -16
@@ -1,171 +0,0 @@
1
- require_dependency 'spree/api/controller_setup'
2
-
3
- module Spree
4
- module Api
5
- class BaseController < ActionController::API
6
- include Spree::Api::ControllerSetup
7
- include Spree::Core::ControllerHelpers::Store
8
- include Spree::Core::ControllerHelpers::StrongParameters
9
- include Spree::Core::ControllerHelpers::Locale
10
- include Spree::Core::ControllerHelpers::Currency
11
-
12
- attr_accessor :current_api_user
13
-
14
- before_action :set_content_type
15
- before_action :load_user
16
- before_action :authorize_for_order, if: proc { order_token.present? }
17
- before_action :authenticate_user
18
- before_action :load_user_roles
19
-
20
- rescue_from ActionController::ParameterMissing, with: :error_during_processing
21
- rescue_from ActiveRecord::RecordInvalid, with: :error_during_processing
22
- rescue_from ActiveRecord::RecordNotFound, with: :not_found
23
- rescue_from CanCan::AccessDenied, with: :unauthorized
24
- rescue_from Spree::Core::GatewayError, with: :gateway_error
25
-
26
- helper Spree::Api::ApiHelpers
27
-
28
- # users should be able to set price when importing orders via api
29
- def permitted_line_item_attributes
30
- if @current_user_roles.include?('admin')
31
- super + [:price, :variant_id, :sku]
32
- else
33
- super
34
- end
35
- end
36
-
37
- def content_type
38
- case params[:format]
39
- when 'json'
40
- 'application/json; charset=utf-8'
41
- when 'xml'
42
- 'text/xml; charset=utf-8'
43
- end
44
- end
45
-
46
- private
47
-
48
- def set_content_type
49
- headers['Content-Type'] = content_type
50
- end
51
-
52
- def load_user
53
- @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
54
- end
55
-
56
- def authenticate_user
57
- return if @current_api_user
58
-
59
- if requires_authentication? && api_key.blank? && order_token.blank?
60
- must_specify_api_key and return
61
- elsif order_token.blank? && (requires_authentication? || api_key.present?)
62
- invalid_api_key and return
63
- else
64
- # An anonymous user
65
- @current_api_user = Spree.user_class.new
66
- end
67
- end
68
-
69
- def invalid_api_key
70
- render 'spree/api/errors/invalid_api_key', status: 401
71
- end
72
-
73
- def must_specify_api_key
74
- render 'spree/api/errors/must_specify_api_key', status: 401
75
- end
76
-
77
- def load_user_roles
78
- @current_user_roles = @current_api_user ? @current_api_user.spree_roles.pluck(:name) : []
79
- end
80
-
81
- def unauthorized
82
- render 'spree/api/errors/unauthorized', status: 401 and return
83
- end
84
-
85
- def error_during_processing(exception)
86
- message = if exception.respond_to?(:original_message)
87
- exception.original_message
88
- else
89
- exception.message
90
- end
91
-
92
- Rails.logger.error message
93
- Rails.logger.error exception.backtrace.join("\n")
94
-
95
- unprocessable_entity(message)
96
- end
97
-
98
- def unprocessable_entity(message)
99
- render plain: { exception: message }.to_json, status: 422
100
- end
101
-
102
- def gateway_error(exception)
103
- @order.errors.add(:base, exception.message)
104
- invalid_resource!(@order)
105
- end
106
-
107
- def requires_authentication?
108
- Spree::Api::Config[:requires_authentication]
109
- end
110
-
111
- def not_found
112
- render 'spree/api/errors/not_found', status: 404 and return
113
- end
114
-
115
- def current_ability
116
- Spree::Dependencies.ability_class.constantize.new(current_api_user)
117
- end
118
-
119
- def invalid_resource!(resource)
120
- @resource = resource
121
- render 'spree/api/errors/invalid_resource', status: 422
122
- end
123
-
124
- def api_key
125
- request.headers['X-Spree-Token'] || params[:token]
126
- end
127
- helper_method :api_key
128
-
129
- def order_token
130
- request.headers['X-Spree-Order-Token'] || params[:order_token]
131
- end
132
-
133
- def find_product(id)
134
- @product = product_scope.friendly.distinct(false).find(id.to_s)
135
- rescue ActiveRecord::RecordNotFound
136
- @product = product_scope.find_by(id: id)
137
- not_found unless @product
138
- end
139
-
140
- def product_scope
141
- if @current_user_roles.include?('admin')
142
- scope = Product.with_deleted.accessible_by(current_ability, :show).includes(*product_includes)
143
-
144
- scope = scope.not_deleted unless params[:show_deleted]
145
- scope = scope.not_discontinued unless params[:show_discontinued]
146
- else
147
- scope = Product.accessible_by(current_ability, :show).active.includes(*product_includes)
148
- end
149
-
150
- scope
151
- end
152
-
153
- def variants_associations
154
- [{ option_values: :option_type }, :default_price, :images]
155
- end
156
-
157
- def product_includes
158
- [:option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations]
159
- end
160
-
161
- def order_id
162
- params[:order_id] || params[:checkout_id] || params[:order_number]
163
- end
164
-
165
- def authorize_for_order
166
- @order = Spree::Order.find_by(number: order_id)
167
- authorize! :show, @order, order_token
168
- end
169
- end
170
- end
171
- end
@@ -1,46 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class AddressesController < Spree::Api::BaseController
5
- before_action :find_order
6
-
7
- def show
8
- authorize! :show, @order, order_token
9
- @address = find_address
10
- respond_with(@address)
11
- end
12
-
13
- def update
14
- authorize! :update, @order, order_token
15
- @address = find_address
16
-
17
- if @address.update(address_params)
18
- respond_with(@address, default_template: :show)
19
- else
20
- invalid_resource!(@address)
21
- end
22
- end
23
-
24
- private
25
-
26
- def address_params
27
- params.require(:address).permit(permitted_address_attributes)
28
- end
29
-
30
- def find_order
31
- @order = Spree::Order.find_by!(number: order_id)
32
- end
33
-
34
- def find_address
35
- if @order.bill_address_id == params[:id].to_i
36
- @order.bill_address
37
- elsif @order.ship_address_id == params[:id].to_i
38
- @order.ship_address
39
- else
40
- raise CanCan::AccessDenied
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,106 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class CheckoutsController < Spree::Api::BaseController
5
- before_action :load_order_with_lock, only: [:next, :advance, :update]
6
-
7
- def next
8
- authorize! :update, @order, order_token
9
- @order.next!
10
- respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
11
- rescue StateMachines::InvalidTransition
12
- respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
13
- end
14
-
15
- def advance
16
- authorize! :update, @order, order_token
17
- while @order.next; end
18
- respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
19
- end
20
-
21
- def update
22
- authorize! :update, @order, order_token
23
-
24
- if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
25
- if current_api_user.has_spree_role?('admin') && user_id.present?
26
- @order.associate_user!(Spree.user_class.find(user_id))
27
- end
28
-
29
- log_state_changes if params[:state]
30
-
31
- return if after_update_attributes
32
-
33
- if @order.completed? || @order.next
34
- state_callback(:after)
35
- respond_with(@order, default_template: 'spree/api/v1/orders/show')
36
- else
37
- respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
38
- end
39
- else
40
- invalid_resource!(@order)
41
- end
42
- end
43
-
44
- private
45
-
46
- def user_id
47
- params[:order][:user_id] if params[:order]
48
- end
49
-
50
- # Should be overridden if you have areas of your checkout that don't match
51
- # up to a step within checkout_steps, such as a registration step
52
- def skip_state_validation?
53
- false
54
- end
55
-
56
- def load_order(lock = false)
57
- @order = Spree::Order.lock(lock).find_by!(number: params[:id])
58
- raise_insufficient_quantity and return if @order.insufficient_stock_lines.present?
59
- @order.state = params[:state] if params[:state]
60
- state_callback(:before)
61
- end
62
-
63
- def load_order_with_lock
64
- load_order(true)
65
- end
66
-
67
- def raise_insufficient_quantity
68
- respond_with(@order, default_template: 'spree/api/v1/orders/insufficient_quantity', status: 422)
69
- end
70
-
71
- def state_callback(before_or_after = :before)
72
- method_name = :"#{before_or_after}_#{@order.state}"
73
- send(method_name) if respond_to?(method_name, true)
74
- end
75
-
76
- def after_update_attributes
77
- if params[:order] && params[:order][:coupon_code].present?
78
- handler = PromotionHandler::Coupon.new(@order)
79
- handler.apply
80
-
81
- if handler.error.present?
82
- @coupon_message = handler.error
83
- respond_with(@order, default_template: 'spree/api/v1/orders/could_not_apply_coupon', status: 422)
84
- return true
85
- end
86
- end
87
- false
88
- end
89
-
90
- def log_state_changes
91
- if @order.previous_changes[:state]
92
- @order.log_state_changes(
93
- state_name: 'order',
94
- old_state: @order.previous_changes[:state].first,
95
- new_state: @order.previous_changes[:state].last
96
- )
97
- end
98
- end
99
-
100
- def order_id
101
- super || params[:id]
102
- end
103
- end
104
- end
105
- end
106
- end
@@ -1,21 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class ClassificationsController < Spree::Api::BaseController
5
- def update
6
- authorize! :update, Product
7
- authorize! :update, Taxon
8
- classification = Spree::Classification.find_by(
9
- product_id: params[:product_id],
10
- taxon_id: params[:taxon_id]
11
- )
12
- Spree::Dependencies.classification_reposition_service.constantize.call(
13
- classification: classification,
14
- position: params[:position]
15
- )
16
- head :ok
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,22 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class CountriesController < Spree::Api::BaseController
5
- skip_before_action :authenticate_user
6
-
7
- def index
8
- @countries = Country.accessible_by(current_ability).ransack(params[:q]).result.
9
- order('name ASC').
10
- page(params[:page]).per(params[:per_page])
11
- country = Country.order('updated_at ASC').last
12
- respond_with(@countries) if stale?(country)
13
- end
14
-
15
- def show
16
- @country = Country.accessible_by(current_ability, :show).find(params[:id])
17
- respond_with(@country)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class CreditCardsController < Spree::Api::BaseController
5
- before_action :user
6
-
7
- def index
8
- @credit_cards = user.
9
- credit_cards.
10
- accessible_by(current_ability).
11
- with_payment_profile.
12
- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
13
- respond_with(@credit_cards)
14
- end
15
-
16
- private
17
-
18
- def user
19
- if params[:user_id].present?
20
- @user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:user_id])
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,25 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class CustomerReturnsController < Spree::Api::BaseController
5
- def index
6
- collection(Spree::CustomerReturn)
7
- respond_with(@collection)
8
- end
9
-
10
- private
11
-
12
- def collection(resource)
13
- return @collection if @collection.present?
14
-
15
- params[:q] ||= {}
16
-
17
- @collection = resource.all
18
- # @search needs to be defined as this is passed to search_form_for
19
- @search = @collection.ransack(params[:q])
20
- @collection = @search.result.order(created_at: :desc).page(params[:page]).per(params[:per_page])
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,58 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class ImagesController < Spree::Api::BaseController
5
- def index
6
- @images = scope.images.accessible_by(current_ability)
7
- respond_with(@images)
8
- end
9
-
10
- def show
11
- @image = Image.accessible_by(current_ability, :show).find(params[:id])
12
- respond_with(@image)
13
- end
14
-
15
- def new; end
16
-
17
- def create
18
- authorize! :create, Image
19
- @image = scope.images.new(image_params)
20
- if @image.save
21
- respond_with(@image, status: 201, default_template: :show)
22
- else
23
- invalid_resource!(@image)
24
- end
25
- end
26
-
27
- def update
28
- @image = scope.images.accessible_by(current_ability, :update).find(params[:id])
29
- if @image.update(image_params)
30
- respond_with(@image, default_template: :show)
31
- else
32
- invalid_resource!(@image)
33
- end
34
- end
35
-
36
- def destroy
37
- @image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])
38
- @image.destroy
39
- respond_with(@image, status: 204)
40
- end
41
-
42
- private
43
-
44
- def image_params
45
- params.require(:image).permit(permitted_image_attributes)
46
- end
47
-
48
- def scope
49
- if params[:product_id]
50
- Spree::Product.friendly.find(params[:product_id])
51
- elsif params[:variant_id]
52
- Spree::Variant.find(params[:variant_id])
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,54 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class InventoryUnitsController < Spree::Api::BaseController
5
- before_action :prepare_event, only: :update
6
-
7
- def show
8
- @inventory_unit = inventory_unit
9
- respond_with(@inventory_unit)
10
- end
11
-
12
- def update
13
- authorize! :update, inventory_unit.order
14
-
15
- inventory_unit.transaction do
16
- if inventory_unit.update(inventory_unit_params)
17
- fire
18
- render :show, status: 200
19
- else
20
- invalid_resource!(inventory_unit)
21
- end
22
- end
23
- end
24
-
25
- private
26
-
27
- def inventory_unit
28
- @inventory_unit ||= InventoryUnit.accessible_by(current_ability, :show).find(params[:id])
29
- end
30
-
31
- def prepare_event
32
- return unless @event = params[:fire]
33
-
34
- can_event = "can_#{@event}?"
35
-
36
- unless inventory_unit.respond_to?(can_event) &&
37
- inventory_unit.send(can_event)
38
- render plain: { exception: "cannot transition to #{@event}" }.to_json,
39
- status: 200
40
- false
41
- end
42
- end
43
-
44
- def fire
45
- inventory_unit.send("#{@event}!") if @event
46
- end
47
-
48
- def inventory_unit_params
49
- params.require(:inventory_unit).permit(permitted_inventory_unit_attributes)
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,70 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class LineItemsController < Spree::Api::BaseController
5
- class_attribute :line_item_options
6
-
7
- self.line_item_options = []
8
-
9
- def new; end
10
-
11
- def create
12
- variant = Spree::Variant.find(params[:line_item][:variant_id])
13
-
14
- @line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: order,
15
- variant: variant,
16
- quantity: params[:line_item][:quantity],
17
- options: line_item_params[:options]).value
18
- if @line_item.errors.empty?
19
- respond_with(@line_item, status: 201, default_template: :show)
20
- else
21
- invalid_resource!(@line_item)
22
- end
23
- end
24
-
25
- def update
26
- @line_item = find_line_item
27
-
28
- if Spree::Dependencies.cart_update_service.constantize.call(order: @order, params: line_items_attributes).success?
29
- @line_item.reload
30
- respond_with(@line_item, default_template: :show)
31
- else
32
- invalid_resource!(@line_item)
33
- end
34
- end
35
-
36
- def destroy
37
- @line_item = find_line_item
38
- Spree::Dependencies.cart_remove_line_item_service.constantize.call(order: @order, line_item: @line_item)
39
-
40
- respond_with(@line_item, status: 204)
41
- end
42
-
43
- private
44
-
45
- def order
46
- @order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
47
- authorize! :update, @order, order_token
48
- end
49
-
50
- def find_line_item
51
- id = params[:id].to_i
52
- order.line_items.detect { |line_item| line_item.id == id } or
53
- raise ActiveRecord::RecordNotFound
54
- end
55
-
56
- def line_items_attributes
57
- { line_items_attributes: {
58
- id: params[:id],
59
- quantity: params[:line_item][:quantity],
60
- options: line_item_params[:options] || {}
61
- } }
62
- end
63
-
64
- def line_item_params
65
- params.require(:line_item).permit(:quantity, :variant_id, options: line_item_options)
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,60 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class OptionTypesController < Spree::Api::BaseController
5
- def index
6
- @option_types = if params[:ids]
7
- Spree::OptionType.
8
- includes(:option_values).
9
- accessible_by(current_ability).
10
- where(id: params[:ids].split(','))
11
- else
12
- Spree::OptionType.
13
- includes(:option_values).
14
- accessible_by(current_ability).
15
- load.ransack(params[:q]).result
16
- end
17
- respond_with(@option_types)
18
- end
19
-
20
- def show
21
- @option_type = Spree::OptionType.accessible_by(current_ability, :show).find(params[:id])
22
- respond_with(@option_type)
23
- end
24
-
25
- def new; end
26
-
27
- def create
28
- authorize! :create, Spree::OptionType
29
- @option_type = Spree::OptionType.new(option_type_params)
30
- if @option_type.save
31
- render :show, status: 201
32
- else
33
- invalid_resource!(@option_type)
34
- end
35
- end
36
-
37
- def update
38
- @option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
39
- if @option_type.update(option_type_params)
40
- render :show
41
- else
42
- invalid_resource!(@option_type)
43
- end
44
- end
45
-
46
- def destroy
47
- @option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
48
- @option_type.destroy
49
- render plain: nil, status: 204
50
- end
51
-
52
- private
53
-
54
- def option_type_params
55
- params.require(:option_type).permit(permitted_option_type_attributes)
56
- end
57
- end
58
- end
59
- end
60
- end