Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v2 api #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Spree
module Api
module V2
module Storefront
class SlideLocationsController < ::Spree::Api::V2::BaseController
def show
render_serialized_payload { serialize_resource(resource) }
end

private

def scope
Spree::SlideLocation
end

def resource
scope.find(params[:id])
end

def resource_serializer
Spree::V2::Storefront::SlideLocationSerializer
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions app/models/spree/slide.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Spree::Slide < ActiveRecord::Base
include Rails.application.routes.url_helpers

has_and_belongs_to_many :slide_locations,
class_name: 'Spree::SlideLocation',
join_table: 'spree_slide_slide_locations'
Expand Down Expand Up @@ -47,6 +49,11 @@ def thumbnail
image_form(:thumbnail)
end

def slide_image_url
# For Api
rails_blob_path(image, only_path: true)
end

private

def image_form(form)
Expand Down
13 changes: 13 additions & 0 deletions app/serializers/spree/v2/storefront/slide_location_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Spree
module V2
module Storefront
class SlideLocationSerializer < BaseSerializer
set_type :slide_location

attributes :name

has_many :slides
end
end
end
end
12 changes: 12 additions & 0 deletions app/serializers/spree/v2/storefront/slide_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Spree
module V2
module Storefront
class SlideSerializer < BaseSerializer
set_type :slide

attributes :name, :body, :slide_name, :slide_link, :slide_image_url

end
end
end
end
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@

resources :slide_locations
end

namespace :api, defaults: { format: 'json' } do
namespace :v2 do
namespace :storefront do
resources :slide_locations, only: [:show]
end
end
end
end