Skip to content

Create products on backend #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ProductsController < AuthorizedController
end
3 changes: 3 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Product < ApplicationRecord
validates :product_name, presence: true, uniqueness: true
end
3 changes: 3 additions & 0 deletions app/resources/product_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ProductResource < JSONAPI::Resource
attributes :product_name
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
jsonapi_resources :categories
jsonapi_resources :comments
jsonapi_resources :posts
jsonapi_resources :products
jsonapi_resources :users
jsonapi_resources :roles
end
19 changes: 19 additions & 0 deletions db/migrate/20170516130257_create_products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateProducts < ActiveRecord::Migration[5.0]
def change
create_table :products do |t|
t.string :product_name
t.integer :supplier_id
t.integer :category_id
t.string :quantity_per_unit
t.float :unit_price
t.integer :units_in_stock
t.integer :units_on_order
t.integer :reorder_level
t.boolean :discontinued
t.datetime :created_at
t.datetime :updated_at

t.timestamps
end
end
end
4 changes: 4 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -16,3 +16,7 @@
u = User.create!(email: "user#{n}@example.com", password: 'Secret123', confirmed_at: Time.now)
u.add_role n == 0 ? :admin : :user
end

20.times do |n|
FactoryGirl.create(:product)
end
7 changes: 7 additions & 0 deletions spec/factories/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :product do
sequence :product_name do |n|
"#{Faker::Pokemon.name} + #{n}"
end
end
end