Skip to content

Commit d58c119

Browse files
committed
Add products
1 parent 2fb5362 commit d58c119

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ProductsController < AuthorizedController
2+
end

app/models/product.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Product < ApplicationRecord
2+
validates :product_name, presence: true, uniqueness: true
3+
end

app/resources/product_resource.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ProductResource < JSONAPI::Resource
2+
attributes :product_name
3+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
jsonapi_resources :categories
44
jsonapi_resources :comments
55
jsonapi_resources :posts
6+
jsonapi_resources :products
67
jsonapi_resources :users
78
jsonapi_resources :roles
89
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class CreateProducts < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table :products do |t|
4+
t.string :product_name
5+
t.integer :supplier_id
6+
t.integer :category_id
7+
t.string :quantity_per_unit
8+
t.float :unit_price
9+
t.integer :units_in_stock
10+
t.integer :units_on_order
11+
t.integer :reorder_level
12+
t.boolean :discontinued
13+
t.datetime :created_at
14+
t.datetime :updated_at
15+
16+
t.timestamps
17+
end
18+
end
19+
end

db/seeds.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
u = User.create!(email: "user#{n}@example.com", password: 'Secret123', confirmed_at: Time.now)
1717
u.add_role n == 0 ? :admin : :user
1818
end
19+
20+
20.times do |n|
21+
FactoryGirl.create(:product)
22+
end

spec/factories/product.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FactoryGirl.define do
2+
factory :product do
3+
sequence :product_name do |n|
4+
"#{Faker::Pokemon.name} + #{n}"
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)