summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/product.rb17
-rw-r--r--db/migrate/20230314020111_create_products.rb15
-rw-r--r--spec/models/product_spec.rb5
3 files changed, 37 insertions, 0 deletions
diff --git a/app/models/product.rb b/app/models/product.rb
new file mode 100644
index 0000000..d12cd41
--- /dev/null
+++ b/app/models/product.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+# Product
+# public_id:string
+# name:string
+# unitary_price:float
+# bulk_price:float
+# picture:attachment
+# available_quantity:integer
+# categories:text
+class Product < ApplicationRecord
+ belongs_to :company
+
+ has_one_attached :picture
+
+ serialize :categories, Array
+end
diff --git a/db/migrate/20230314020111_create_products.rb b/db/migrate/20230314020111_create_products.rb
new file mode 100644
index 0000000..f28e9d1
--- /dev/null
+++ b/db/migrate/20230314020111_create_products.rb
@@ -0,0 +1,15 @@
+class CreateProducts < ActiveRecord::Migration[7.0]
+ def change
+ create_table :products do |t|
+ t.string :public_id
+ t.string :name
+ t.float :unitary_price
+ t.float :bulk_price
+ t.references :company, null: false, foreign_key: true
+ t.integer :available_quantity
+ t.text :categories
+
+ t.timestamps
+ end
+ end
+end
diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb
new file mode 100644
index 0000000..f22fbfd
--- /dev/null
+++ b/spec/models/product_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Product, type: :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end