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

Storefront account API for fetching vendors associated to a user #4

Open
wants to merge 1 commit into
base: features/vendor-creation-from-storefront
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,35 @@
module Spree

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are in the branch: tests/tests-for-new-changes

module Api
module V2
module Storefront
module Account
class UserVendorsController < Spree::Api::V2::ResourceController
before_action :require_spree_current_user

def index
render_serialized_payload { serialize_collection(paginated_collection) }
end

private

def resource
resource_finder.user_vendors(spree_current_user)
end

def collection_serializer
Spree::V2::Storefront::VendorSerializer
end

def paginated_collection
collection_paginator.new(resource, params).call
end

def resource_finder
Spree::Vendor
end
end
end
end
end
end
end
4 changes: 4 additions & 0 deletions app/models/spree/vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def update_notification_email(email)
update(notification_email: email)
end

def self.user_vendors(user)
user.vendors
end

private

def create_stock_location
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
namespace :v2 do
namespace :storefront do
resources :vendors, only: %i[show index create update destroy]

namespace :account do
resources :vendors, controller: :user_vendors, only: %i[index]
end
end
end
end
Expand Down