Skip to content

Commit fa36dcf

Browse files
authored
Merge pull request #16 from czikarito/add_products
Create products on backend
2 parents 1dd32a9 + d58c119 commit fa36dcf

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
jsonapi_resources :customers
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
@@ -28,3 +28,7 @@
2828
25.times do |n|
2929
FactoryGirl.create(:customer)
3030
end
31+
32+
20.times do |n|
33+
FactoryGirl.create(:product)
34+
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)