Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Move back into BaseController some methods moved previously to ResourceController

Damian Legawiec0cb9456cd71b
diff --git a/api/app/controllers/spree/api/v2/base_controller.rb b/api/app/controllers/spree/api/v2/base_controller.rb
index d8debcb733..8ef5d83d6f 100644
--- a/api/app/controllers/spree/api/v2/base_controller.rb
+++ b/api/app/controllers/spree/api/v2/base_controller.rb
@@ -15,6 +15,32 @@ module Spree
Spree::Api::Config[:api_v2_content_type]
end
+ protected
+
+ def serialize_collection(collection)
+ collection_serializer.new(
+ collection,
+ collection_options(collection).merge(params: serializer_params)
+ ).serializable_hash
+ end
+
+ def serialize_resource(resource)
+ resource_serializer.new(
+ resource,
+ params: serializer_params,
+ include: resource_includes,
+ fields: sparse_fields
+ ).serializable_hash
+ end
+
+ def paginated_collection
+ collection_paginator.new(sorted_collection, params).call
+ end
+
+ def collection_paginator
+ Spree::Api::Dependencies.storefront_collection_paginator.constantize
+ end
+
def render_serialized_payload(status = 200)
render json: yield, status: status, content_type: content_type
rescue ArgumentError => exception
diff --git a/api/app/controllers/spree/api/v2/resource_controller.rb b/api/app/controllers/spree/api/v2/resource_controller.rb
index 2730029e2b..bdfc5e1d80 100644
--- a/api/app/controllers/spree/api/v2/resource_controller.rb
+++ b/api/app/controllers/spree/api/v2/resource_controller.rb
@@ -14,30 +14,6 @@ module Spree
protected
- def serialize_collection(collection)
- collection_serializer.new(
- collection,
- collection_options(collection).merge(params: serializer_params)
- ).serializable_hash
- end
-
- def serialize_resource(resource)
- resource_serializer.new(
- resource,
- params: serializer_params,
- include: resource_includes,
- fields: sparse_fields
- ).serializable_hash
- end
-
- def paginated_collection
- collection_paginator.new(sorted_collection, params).call
- end
-
- def collection_paginator
- Spree::Api::Dependencies.storefront_collection_paginator.constantize
- end
-
def sorted_collection
collection_sorter.new(collection, params, allowed_sort_attributes).call
end