summaryrefslogtreecommitdiff
path: root/app/controllers/serializers/product_serializer.rb
blob: 4a2158d1a34640a1f451335d0ce7369b9282b5da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

module Serializers
  # ProductSerializer
  class ProductSerializer < BaseSerializer
    extend ActionView::RoutingUrlFor

    attributes :name, :unitary_price, :bulk_price, :available_quantity, :categories

    attribute :picture do |object|
      object.picture.url
    end

    belongs_to :company, links: {
      self: :url,
      related: lambda(object) {
        company_path(object.company)
      }
    }
  end
end