diff --git a/app/controllers/spree/api/v2/storefront/account/user_vendors_controller.rb b/app/controllers/spree/api/v2/storefront/account/user_vendors_controller.rb new file mode 100644 index 00000000..63d8acb0 --- /dev/null +++ b/app/controllers/spree/api/v2/storefront/account/user_vendors_controller.rb @@ -0,0 +1,35 @@ +module Spree + 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 diff --git a/app/models/spree/vendor.rb b/app/models/spree/vendor.rb index f650a38e..7f7de24e 100644 --- a/app/models/spree/vendor.rb +++ b/app/models/spree/vendor.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 7af0e5ec..596038ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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