Class: OpenaiFeed

Inherits:
ApplicationRecord show all
Defined in:
app/models/openai_feed.rb

Overview

== Schema Information

Table name: openai_feeds
Database name: primary

id :bigint not null, primary key
json_data :jsonb not null
locale :string not null
sku :string not null
target_country_iso :string not null
created_at :datetime not null
updated_at :datetime not null
catalog_id :integer not null
catalog_item_id :integer not null

Indexes

index_openai_feeds_on_catalog_id (catalog_id)
index_openai_feeds_on_catalog_item_id (catalog_item_id) UNIQUE

Foreign Keys

fk_rails_... (catalog_id => catalogs.id) ON DELETE => cascade
fk_rails_... (catalog_item_id => catalog_items.id) ON DELETE => cascade

Belongs to collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.full_json(catalog) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/openai_feed.rb', line 29

def self.full_json(catalog)
  company_name = catalog.company.legal_name
  locale = catalog.locale_for_catalog
  product_data = OpenaiFeed.where(catalog_id: catalog.id)
  last_updated = product_data.maximum(:updated_at) || Time.current

  {
    feed_info: {
      title: "#{company_name} Product Feed",
      description: 'Product feed for OpenAI Agentic Commerce',
      last_updated: last_updated.iso8601,
      total_products: product_data.count,
      locale: locale
    },
    products: product_data.pluck(:json_data)
  }
end

Instance Method Details

#catalog_itemCatalogItem



27
# File 'app/models/openai_feed.rb', line 27

belongs_to :catalog_item