Class: Dscf::Marketplace::AggregatorListingsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Core::Common
Defined in:
app/controllers/dscf/marketplace/aggregator_listings_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#bypass_permissions_for_demo?, #pundit_user

Instance Method Details

#feedObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/dscf/marketplace/aggregator_listings_controller.rb', line 6

def feed
  authorize @clazz.new, :index?
  # Retailer-facing feed: only listings that are truly offerable — own
  # status :active AND (for supplier-sourced) the supplier hasn't paused
  # or run out of stock. A listing whose supplier paused drops out here.
  listings = @clazz.active
    .includes(:product, {supplier_product: :product}, {sub_supplier_product: :product})
    .select(&:available?)

  options = {
    include: default_serializer_includes[:index] || [],
    meta: {resource_type: "aggregator_feed"}
  }

  render_success(data: listings, serializer_options: options)
end

#my_listingsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dscf/marketplace/aggregator_listings_controller.rb', line 23

def my_listings
  authorize @clazz.new, :my_listings?
  businesses = current_user.businesses.pluck(:id)
  listings = @clazz.where(aggregator_id: businesses).includes(:product, {supplier_product: :product}, {sub_supplier_product: :product})

  options = {
    include: default_serializer_includes[:index] || [],
    meta: {resource_type: "my_aggregator_listings"}
  }

  render_success(data: listings, serializer_options: options)
end