Skip to content

Commit 8184917

Browse files
authored
Merge branch 'master' into orders
2 parents 82146f6 + fa36dcf commit 8184917

18 files changed

+146
-0
lines changed
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class CustomersController < AuthorizedController
2+
3+
end
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ProductsController < AuthorizedController
2+
end
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SuppliersController < AuthorizedController
2+
end

app/models/customer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Customer < ApplicationRecord
2+
end

app/models/product.rb

+3
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/models/supplier.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Supplier < ApplicationRecord
2+
end

app/resources/customer_resource.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CustomerResource < JSONAPI::Resource
2+
attributes :company_name,
3+
:contact_name
4+
:contact_title
5+
:address
6+
:city
7+
:region
8+
:postal_code
9+
:country
10+
:phone
11+
:fax
12+
end

app/resources/product_resource.rb

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

app/resources/supplier_resource.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class SupplierResource < JSONAPI::Resource
2+
attributes :company_name,
3+
:contact_name,
4+
:contact_title,
5+
:address,
6+
:city,
7+
:region,
8+
:postal_code,
9+
:country,
10+
:phone,
11+
:fax,
12+
:home_page
13+
end

config/routes.rb

+3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
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 :orders
10+
jsonapi_resources :customers
11+
jsonapi_resources :suppliers
912
end
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateCustomers < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table :customers, force: true do |t|
4+
t.string :company_name
5+
t.string :contact_name
6+
t.string :contact_title
7+
t.string :address
8+
t.string :city
9+
t.string :region
10+
t.string :postal_code
11+
t.string :country
12+
t.string :phone
13+
t.string :fax
14+
t.datetime :created_at
15+
t.datetime :updated_at
16+
end
17+
end
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateSuppliers < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table(:suppliers) do |t|
4+
t.string :company_name
5+
t.string :contact_name
6+
t.string :contact_title
7+
t.string :address
8+
t.string :city
9+
t.string :region
10+
t.string :postal_code
11+
t.string :country
12+
t.string :phone
13+
t.string :fax
14+
t.text :home_page
15+
t.timestamps
16+
end
17+
end
18+
end

db/seeds.rb

+11
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@
2121
FactoryGirl.create(:order)
2222
end
2323

24+
25.times do |n|
25+
FactoryGirl.create(:supplier)
26+
end
27+
28+
25.times do |n|
29+
FactoryGirl.create(:customer)
30+
end
31+
32+
20.times do |n|
33+
FactoryGirl.create(:product)
34+
end

server/tmp/restart.txt

Whitespace-only changes.

spec/factories/customer.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FactoryGirl.define do
2+
factory :customer do
3+
company_name { Faker::Company.name }
4+
contact_name { Faker::Name.name }
5+
address { Faker::Address.street_address }
6+
city { Faker::Address.city }
7+
region { Faker::Address.state }
8+
postal_code { Faker::Address.zip_code }
9+
country { Faker::Address.country }
10+
phone { Faker::PhoneNumber.phone_number }
11+
fax { Faker::PhoneNumber.phone_number }
12+
end
13+
end

spec/factories/product.rb

+7
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

spec/factories/supplier.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FactoryGirl.define do
2+
factory :supplier do
3+
company_name { Faker::Company.name }
4+
contact_name { Faker::Name.name }
5+
contact_title { Faker::Name.title }
6+
address { Faker::Address.street_address }
7+
city { Faker::Address.city }
8+
region { Faker::Address.state }
9+
postal_code { Faker::Address.postcode }
10+
country { Faker::Address.country }
11+
phone { Faker::PhoneNumber.cell_phone }
12+
fax { Faker::PhoneNumber.cell_phone }
13+
home_page { "http://#{Faker::Company.name}.com" }
14+
end
15+
end

0 commit comments

Comments
 (0)