Skip to content

Commit

Permalink
[SD-1476] - Add OpenAPI documentation to Platform API for CMS Pages a…
Browse files Browse the repository at this point in the history
…nd CMS Sections (#11364)

* Add CMS Pages to Platform openAPI Docs

* Add cms_sections platform API docs

* Add documentation for reposition cms_section

* Fix CC issue and improve test for no param error.
  • Loading branch information
MatthewKennedy committed Sep 29, 2021
1 parent bab28d3 commit 60e2ab4
Show file tree
Hide file tree
Showing 12 changed files with 1,233 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ class CmsSectionsController < ResourceController
def reposition
spree_authorize! :update, @moved_section if spree_current_user.present?

@moved_section = scope.find(params[:section_id])
unless params[:new_position_idx].present?
render json: { error: I18n.t('spree.api.v2.cms_sections.pass_position_index') }, status: 422
return
end

@moved_section = scope.find(params[:id])
new_index = params[:new_position_idx].to_i + 1

if @moved_section && new_index
Expand All @@ -18,7 +23,7 @@ def reposition
end

if @moved_section.save
head :no_content
render_serialized_payload { serialize_resource(resource) }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module V2
module Platform
class CmsSectionSerializer < BaseSerializer
include ::Spree::Api::V2::ResourceSerializerConcern

belongs_to :cms_page, serializer: :cms_page
belongs_to :linked_resource, polymorphic: {
Spree::Cms::Pages::StandardPage => :cms_page,
Spree::Cms::Pages::FeaturePage => :cms_page,
Spree::Cms::Pages::Homepage => :cms_page
}
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ class CmsSectionSerializer < BaseSerializer
section.fullscreen?
end

belongs_to :linked_resource, polymorphic: true
belongs_to :linked_resource, polymorphic: {
Spree::Cms::Pages::StandardPage => :cms_page,
Spree::Cms::Pages::FeaturePage => :cms_page,
Spree::Cms::Pages::Homepage => :cms_page
}
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions api/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ en:
wrong_quantity: "Quantity has to be greater than 0"
pass_variant_id: "Pass the variant id that you want to add to this wishlist, eg.{ variant_id: 20 }"
must_be_an_integer: "Sorry, you must pass an integer value, eg. 5"
cms_sections:
pass_position_index: "Pass 'new_position_idx' with an interger value in the request body"
3 changes: 2 additions & 1 deletion api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@
end
end

resource :cms_sections do
# CMS Sections API
resources :cms_sections do
member do
patch :reposition
end
Expand Down
Loading

0 comments on commit 60e2ab4

Please sign in to comment.