diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb new file mode 100644 index 0000000..a3d2be8 --- /dev/null +++ b/app/controllers/employees_controller.rb @@ -0,0 +1,3 @@ +class EmployeesController < AuthorizedController + +end diff --git a/app/models/employee.rb b/app/models/employee.rb new file mode 100644 index 0000000..d5e0233 --- /dev/null +++ b/app/models/employee.rb @@ -0,0 +1,2 @@ +class Employee < ApplicationRecord +end diff --git a/app/resources/employee_resource.rb b/app/resources/employee_resource.rb new file mode 100644 index 0000000..f83211a --- /dev/null +++ b/app/resources/employee_resource.rb @@ -0,0 +1,3 @@ +class EmployeeResource < JSONAPI::Resource + attributes :title, :created_at, :first_name +end diff --git a/config/routes.rb b/config/routes.rb index ce43b3d..05d1585 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ jsonapi_resources :products jsonapi_resources :users jsonapi_resources :roles + jsonapi_resources :employees jsonapi_resources :orders jsonapi_resources :customers jsonapi_resources :suppliers diff --git a/db/migrate/20170516130923_add_employee_table.rb b/db/migrate/20170516130923_add_employee_table.rb new file mode 100644 index 0000000..60e4829 --- /dev/null +++ b/db/migrate/20170516130923_add_employee_table.rb @@ -0,0 +1,24 @@ +class AddEmployeeTable < ActiveRecord::Migration[5.0] + def change + create_table :employees do |t| + t.string :last_name + t.string :first_name + t.string :title + t.string :title_of_courtesy + t.date :birth_date + t.date :hire_date + t.string :address + t.string :city + t.string :region + t.string :postal_code + t.string :country + t.string :home_phone + t.string :extension + t.string :photo + t.text :notes + t.integer :reports_to + t.datetime :created_at + t.datetime :updated_at + end + end +end diff --git a/db/seeds.rb b/db/seeds.rb index b703a58..6f558e3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -32,3 +32,7 @@ 20.times do |n| FactoryGirl.create(:product) end + +20.times do |n| + FactoryGirl.create(:employee) +end diff --git a/db/structure.sql b/db/structure.sql index e734ac0..c8839de 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 9.6.2 --- Dumped by pg_dump version 9.6.2 +-- Dumped from database version 9.6.3 +-- Dumped by pg_dump version 9.6.3 SET statement_timeout = 0; SET lock_timeout = 0; @@ -109,6 +109,52 @@ CREATE SEQUENCE comments_id_seq ALTER SEQUENCE comments_id_seq OWNED BY comments.id; +-- +-- Name: employees; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE employees ( + id integer NOT NULL, + last_name character varying, + first_name character varying, + title character varying, + title_of_courtesy character varying, + birth_date date, + hire_date date, + address character varying, + city character varying, + region character varying, + postal_code character varying, + country character varying, + home_phone character varying, + extension character varying, + photo character varying, + notes text, + reports_to integer, + created_at timestamp without time zone, + updated_at timestamp without time zone +); + + +-- +-- Name: employees_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE employees_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: employees_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE employees_id_seq OWNED BY employees.id; + + -- -- Name: posts; Type: TABLE; Schema: public; Owner: - -- @@ -255,6 +301,13 @@ ALTER TABLE ONLY categories ALTER COLUMN id SET DEFAULT nextval('categories_id_s ALTER TABLE ONLY comments ALTER COLUMN id SET DEFAULT nextval('comments_id_seq'::regclass); +-- +-- Name: employees id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY employees ALTER COLUMN id SET DEFAULT nextval('employees_id_seq'::regclass); + + -- -- Name: posts id; Type: DEFAULT; Schema: public; Owner: - -- @@ -300,6 +353,14 @@ ALTER TABLE ONLY comments ADD CONSTRAINT comments_pkey PRIMARY KEY (id); +-- +-- Name: employees employees_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY employees + ADD CONSTRAINT employees_pkey PRIMARY KEY (id); + + -- -- Name: posts posts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -423,6 +484,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20170328194726'), ('20170418135338'), ('20170504204400'), -('20170508090812'); +('20170508090812'), +('20170516130923'); diff --git a/spec/factories/employee.rb b/spec/factories/employee.rb new file mode 100644 index 0000000..faffd5f --- /dev/null +++ b/spec/factories/employee.rb @@ -0,0 +1,21 @@ +FactoryGirl.define do + factory :employee do + last_name { Faker::Name.last_name } + first_name { Faker::Name.first_name } + title { Faker::Name.title } + title_of_courtesy { Faker::Name.title } + birth_date { Faker::Date.backward(720) } + hire_date { Faker::Date.backward(10) } + address { Faker::Address.street_address } + city { Faker::Address.city } + region { Faker::Address.state } + postal_code { Faker::Address.postcode } + country { Faker::Address.country } + home_phone { Faker::PhoneNumber.phone_number } + extension { 'jpg' } + photo { Faker::Placeholdit.image("50x50") } + notes { Faker::Lorem.paragraph } + created_at { Faker::Date.backward(20) } + updated_at { Faker::Date.backward(15) } + end +end diff --git a/test/controllers/category_controller_test.rb b/test/controllers/category_controller_test.rb new file mode 100644 index 0000000..70bdf31 --- /dev/null +++ b/test/controllers/category_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CategoryControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/employee_controller_test.rb b/test/controllers/employee_controller_test.rb new file mode 100644 index 0000000..fff1809 --- /dev/null +++ b/test/controllers/employee_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class EmployeeControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end