spree_api 4.2.5 → 4.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +14 -1
- data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +23 -0
- data/app/controllers/spree/api/v1/classifications_controller.rb +4 -3
- data/app/controllers/spree/api/v1/orders_controller.rb +5 -1
- data/app/controllers/spree/api/v1/products_controller.rb +2 -2
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -1
- data/app/controllers/spree/api/v2/base_controller.rb +29 -6
- data/app/controllers/spree/api/v2/platform/addresses_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/classifications_controller.rb +43 -0
- data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +34 -0
- data/app/controllers/spree/api/v2/platform/countries_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +35 -0
- data/app/controllers/spree/api/v2/platform/menus_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/option_types_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/option_values_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/products_controller.rb +21 -0
- data/app/controllers/spree/api/v2/platform/resource_controller.rb +112 -0
- data/app/controllers/spree/api/v2/platform/taxons_controller.rb +30 -0
- data/app/controllers/spree/api/v2/platform/users_controller.rb +28 -0
- data/app/controllers/spree/api/v2/resource_controller.rb +18 -6
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +2 -14
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +13 -11
- data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +2 -2
- data/app/controllers/spree/api/v2/storefront/account_controller.rb +32 -1
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +28 -6
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +2 -1
- data/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb +41 -0
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +9 -14
- data/app/controllers/spree/api/v2/storefront/menus_controller.rb +35 -0
- data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +6 -12
- data/app/controllers/spree/api/v2/storefront/stores_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +7 -8
- data/app/helpers/spree/api/v2/display_money_helper.rb +2 -2
- data/app/models/spree/api_configuration.rb +1 -0
- data/app/models/spree/api_dependencies.rb +19 -5
- data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +16 -0
- data/app/serializers/spree/api/v2/base_serializer.rb +32 -0
- data/app/serializers/spree/api/v2/platform/address_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/base_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/classification_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/country_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/image_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +22 -0
- data/app/serializers/spree/api/v2/platform/menu_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/product_serializer.rb +78 -0
- data/app/serializers/spree/api/v2/platform/state_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +20 -0
- data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/store_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +38 -0
- data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/user_serializer.rb +21 -0
- data/app/serializers/spree/api/v2/platform/variant_serializer.rb +57 -0
- data/app/serializers/spree/v2/storefront/base_serializer.rb +3 -2
- data/app/serializers/spree/v2/storefront/cms_page_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +28 -0
- data/app/serializers/spree/v2/storefront/country_serializer.rb +4 -4
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -0
- data/app/serializers/spree/v2/storefront/menu_item_serializer.rb +37 -0
- data/app/serializers/spree/v2/storefront/menu_serializer.rb +13 -0
- data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_serializer.rb +4 -1
- data/app/serializers/spree/v2/storefront/store_serializer.rb +10 -0
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +6 -5
- data/config/initializers/doorkeeper.rb +8 -1
- data/config/initializers/rabl.rb +9 -0
- data/config/routes.rb +115 -3
- data/db/migrate/20210727102516_change_integer_id_columns_type.rb +9 -0
- data/docs/oauth/index.yml +2 -2
- data/docs/v2/platform/index.yaml +1501 -0
- data/docs/v2/storefront/index.yaml +48 -2
- data/lib/spree/api.rb +1 -0
- data/lib/spree/api/engine.rb +6 -17
- data/lib/spree/api/testing_support/v2/base.rb +1 -1
- data/lib/spree/api/testing_support/v2/platform_contexts.rb +214 -0
- data/lib/spree/api/testing_support/v2/serializers_params.rb +14 -0
- data/spree_api.gemspec +3 -0
- metadata +100 -10
- data/app/assets/javascripts/spree/api/main.js +0 -36
- data/app/assets/javascripts/spree/api/storefront/cart.js +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 381bcae626a5cfcc30444d47853c1bc26063befbc5c18db328276d8c1998c309
|
4
|
+
data.tar.gz: 01fc310be446eff60debb73a6da32a1b4e548dcd2ec7e7fca562ef7fada5a248
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03c6087202462b6ff19e3cc1b081a175e3db9273ce486b321c27aa44e4ae82a57c9b73b24894f788c1335584e0cfcf7b94733844f3875d8f4ff67be59ba04acb
|
7
|
+
data.tar.gz: 24ae9980e17d37c7963cdbd7fb1e9ab6a02ef099e7763b83bf8276d9ea8e296ee49e4a3b4c42587a3b02010151f450478c0c376f6c835f8db4e6536fbc33d0fa
|
data/Rakefile
CHANGED
@@ -3,7 +3,6 @@ require 'rake'
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
require 'spree/testing_support/common_rake'
|
6
|
-
require 'rails/all'
|
7
6
|
|
8
7
|
RSpec::Core::RakeTask.new
|
9
8
|
|
@@ -14,3 +13,17 @@ task :test_app do
|
|
14
13
|
ENV['LIB_NAME'] = 'spree/api'
|
15
14
|
Rake::Task['common:test_app'].invoke
|
16
15
|
end
|
16
|
+
|
17
|
+
namespace :rswag do
|
18
|
+
namespace :specs do
|
19
|
+
desc 'Generate Swagger JSON files from integration specs'
|
20
|
+
RSpec::Core::RakeTask.new('swaggerize') do |t|
|
21
|
+
t.pattern = ENV.fetch(
|
22
|
+
'PATTERN',
|
23
|
+
'spec/integration/**/*_spec.rb'
|
24
|
+
)
|
25
|
+
|
26
|
+
t.rspec_opts = ['--format Rswag::Specs::SwaggerFormatter', '--order defined']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module ProductListIncludes
|
5
|
+
def product_list_includes
|
6
|
+
variant_includes = {
|
7
|
+
prices: [],
|
8
|
+
option_values: :option_type,
|
9
|
+
images: []
|
10
|
+
}
|
11
|
+
|
12
|
+
{
|
13
|
+
product_properties: [],
|
14
|
+
option_types: [],
|
15
|
+
variant_images: [],
|
16
|
+
master: variant_includes,
|
17
|
+
variants: variant_includes
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -9,9 +9,10 @@ module Spree
|
|
9
9
|
product_id: params[:product_id],
|
10
10
|
taxon_id: params[:taxon_id]
|
11
11
|
)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
Spree::Dependencies.classification_reposition_service.constantize.call(
|
13
|
+
classification: classification,
|
14
|
+
position: params[:position]
|
15
|
+
)
|
15
16
|
head :ok
|
16
17
|
end
|
17
18
|
end
|
@@ -56,7 +56,7 @@ module Spree
|
|
56
56
|
|
57
57
|
def empty
|
58
58
|
authorize! :update, @order, order_token
|
59
|
-
@order
|
59
|
+
cart_empty_service.call(order: @order)
|
60
60
|
render plain: nil, status: 204
|
61
61
|
end
|
62
62
|
|
@@ -150,6 +150,10 @@ module Spree
|
|
150
150
|
def order_id
|
151
151
|
super || params[:id]
|
152
152
|
end
|
153
|
+
|
154
|
+
def cart_empty_service
|
155
|
+
Spree::Dependencies.cart_empty_service.constantize
|
156
|
+
end
|
153
157
|
end
|
154
158
|
end
|
155
159
|
end
|
@@ -64,7 +64,7 @@ module Spree
|
|
64
64
|
params[:product][:available_on] ||= Time.current
|
65
65
|
set_up_shipping_category
|
66
66
|
|
67
|
-
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
67
|
+
options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }
|
68
68
|
@product = Core::Importer::Product.new(nil, product_params, options).create
|
69
69
|
|
70
70
|
if @product.persisted?
|
@@ -77,7 +77,7 @@ module Spree
|
|
77
77
|
def update
|
78
78
|
authorize! :update, @product
|
79
79
|
|
80
|
-
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
80
|
+
options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }
|
81
81
|
@product = Core::Importer::Product.new(@product, product_params, options).update
|
82
82
|
|
83
83
|
if @product.errors.empty?
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
|
20
20
|
def create
|
21
21
|
authorize! :create, Taxonomy
|
22
|
-
@taxonomy =
|
22
|
+
@taxonomy = current_store.taxonomies.new(taxonomy_params)
|
23
23
|
if @taxonomy.save
|
24
24
|
respond_with(@taxonomy, status: 201, default_template: :show)
|
25
25
|
else
|
@@ -7,8 +7,10 @@ module Spree
|
|
7
7
|
include Spree::Core::ControllerHelpers::Store
|
8
8
|
include Spree::Core::ControllerHelpers::Locale
|
9
9
|
include Spree::Core::ControllerHelpers::Currency
|
10
|
+
|
10
11
|
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
11
12
|
rescue_from CanCan::AccessDenied, with: :access_denied
|
13
|
+
rescue_from Doorkeeper::Errors::DoorkeeperError, with: :access_denied_401
|
12
14
|
rescue_from Spree::Core::GatewayError, with: :gateway_error
|
13
15
|
rescue_from ActionController::ParameterMissing, with: :error_during_processing
|
14
16
|
if defined?(JSONAPI::Serializer::UnsupportedIncludeError)
|
@@ -39,7 +41,7 @@ module Spree
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def paginated_collection
|
42
|
-
collection_paginator.new(sorted_collection, params).call
|
44
|
+
@paginated_collection ||= collection_paginator.new(sorted_collection, params).call
|
43
45
|
end
|
44
46
|
|
45
47
|
def collection_paginator
|
@@ -51,10 +53,22 @@ module Spree
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def render_error_payload(error, status = 422)
|
54
|
-
if error.is_a?(
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
json = if error.is_a?(ActiveModel::Errors)
|
57
|
+
{ error: error.full_messages.to_sentence, errors: error.messages }
|
58
|
+
elsif error.is_a?(Struct)
|
59
|
+
{ error: error.to_s, errors: error.to_h }
|
60
|
+
else
|
61
|
+
{ error: error }
|
62
|
+
end
|
63
|
+
|
64
|
+
render json: json, status: status, content_type: content_type
|
65
|
+
end
|
66
|
+
|
67
|
+
def render_result(result)
|
68
|
+
if result.success?
|
69
|
+
render_serialized_payload { serialize_resource(result.value) }
|
70
|
+
else
|
71
|
+
render_error_payload(result.error)
|
58
72
|
end
|
59
73
|
end
|
60
74
|
|
@@ -114,7 +128,12 @@ module Spree
|
|
114
128
|
end
|
115
129
|
|
116
130
|
def serializer_params
|
117
|
-
{
|
131
|
+
{
|
132
|
+
currency: current_currency,
|
133
|
+
locale: current_locale,
|
134
|
+
store: current_store,
|
135
|
+
user: spree_current_user
|
136
|
+
}
|
118
137
|
end
|
119
138
|
|
120
139
|
def record_not_found
|
@@ -125,6 +144,10 @@ module Spree
|
|
125
144
|
render_error_payload(exception.message, 403)
|
126
145
|
end
|
127
146
|
|
147
|
+
def access_denied_401(exception)
|
148
|
+
render_error_payload(exception.message, 401)
|
149
|
+
end
|
150
|
+
|
128
151
|
def gateway_error(exception)
|
129
152
|
render_error_payload(exception.message)
|
130
153
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class AddressesController < ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_class
|
9
|
+
Spree::Address
|
10
|
+
end
|
11
|
+
|
12
|
+
def scope_includes
|
13
|
+
[:country, :state, :user]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class ClassificationsController < ResourceController
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
7
|
+
|
8
|
+
def reposition
|
9
|
+
spree_authorize! :update, resource if spree_current_user.present?
|
10
|
+
|
11
|
+
result = classification_reposition_service.call(
|
12
|
+
classification: resource,
|
13
|
+
position: permitted_resource_params[:position]
|
14
|
+
)
|
15
|
+
|
16
|
+
if result.success?
|
17
|
+
render_serialized_payload { serialize_resource(result.value) }
|
18
|
+
else
|
19
|
+
render_error_payload(result.error)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def model_class
|
26
|
+
Spree::Classification
|
27
|
+
end
|
28
|
+
|
29
|
+
def scope_includes
|
30
|
+
[
|
31
|
+
taxon: [],
|
32
|
+
product: [:variants_including_master, :variant_images, :master, variants: [:prices]]
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
def classification_reposition_service
|
37
|
+
Spree::Dependencies.classification_reposition_service.constantize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class CmsSectionsController < ResourceController
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
7
|
+
|
8
|
+
def reposition
|
9
|
+
spree_authorize! :update, @moved_section if spree_current_user.present?
|
10
|
+
|
11
|
+
@moved_section = scope.find(params[:section_id])
|
12
|
+
new_index = params[:new_position_idx].to_i + 1
|
13
|
+
|
14
|
+
if @moved_section && new_index
|
15
|
+
@moved_section.set_list_position(new_index)
|
16
|
+
else
|
17
|
+
head :bad_request
|
18
|
+
end
|
19
|
+
|
20
|
+
if @moved_section.save
|
21
|
+
head :no_content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def model_class
|
28
|
+
Spree::CmsSection
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class CountriesController < ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_class
|
9
|
+
Spree::Country
|
10
|
+
end
|
11
|
+
|
12
|
+
def scope_includes
|
13
|
+
[:states, :zones]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class MenuItemsController < ResourceController
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
7
|
+
|
8
|
+
def reposition
|
9
|
+
spree_authorize! :update, @moved_item if spree_current_user.present?
|
10
|
+
|
11
|
+
@moved_item = scope.find(params[:moved_item_id])
|
12
|
+
@new_parent = scope.find(params[:new_parent_id])
|
13
|
+
new_index = params[:new_position_idx].to_i
|
14
|
+
|
15
|
+
if @moved_item && @new_parent && new_index
|
16
|
+
@moved_item.move_to_child_with_index(@new_parent, new_index)
|
17
|
+
else
|
18
|
+
head :bad_request
|
19
|
+
end
|
20
|
+
|
21
|
+
if @moved_item.save
|
22
|
+
head :no_content
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def model_class
|
29
|
+
Spree::MenuItem
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class OptionValuesController < ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_class
|
9
|
+
Spree::OptionValue
|
10
|
+
end
|
11
|
+
|
12
|
+
def scope_includes
|
13
|
+
[:option_type]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class ProductsController < ResourceController
|
6
|
+
include ::Spree::Api::V2::ProductListIncludes
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def model_class
|
11
|
+
Spree::Product
|
12
|
+
end
|
13
|
+
|
14
|
+
def scope_includes
|
15
|
+
product_list_includes
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|