Skip to content

Commit

Permalink
Merge pull request #63 from epintozzi/development
Browse files Browse the repository at this point in the history
Merge development to master
  • Loading branch information
epintozzi authored Dec 2, 2016
2 parents 67add9c + 8caf6fa commit d699819
Show file tree
Hide file tree
Showing 173 changed files with 46,139 additions and 17 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--color
--format=documentation
--require spec_helper
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'


gem 'active_model_serializers', '~> 0.10.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
Expand All @@ -27,6 +27,8 @@ group :development, :test do
gem 'pry'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'simplecov'

end

group :development do
Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
active_model_serializers (0.10.3)
actionpack (>= 4.1, < 6)
activemodel (>= 4.1, < 6)
jsonapi (= 0.1.1.beta2)
activejob (5.0.0.1)
activesupport (= 5.0.0.1)
globalid (>= 0.3.6)
Expand All @@ -44,6 +48,7 @@ GEM
coderay (1.1.1)
concurrent-ruby (1.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
Expand All @@ -54,6 +59,9 @@ GEM
globalid (0.3.7)
activesupport (>= 4.1.0)
i18n (0.7.0)
json (1.8.3)
jsonapi (0.1.1.beta2)
json (~> 1.8)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -124,6 +132,11 @@ GEM
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
Expand All @@ -144,6 +157,7 @@ PLATFORMS
ruby

DEPENDENCIES
active_model_serializers (~> 0.10.0)
byebug
factory_girl_rails
listen (~> 3.0.5)
Expand All @@ -153,6 +167,7 @@ DEPENDENCIES
rails (~> 5.0.0, >= 5.0.0.1)
rb-readline
rspec-rails
simplecov
tzinfo-data

BUNDLED WITH
Expand Down
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# README
# Rales Engine

This README would normally document whatever steps are necessary to get the
application up and running.
This project is a JSON API which exposes the SalesEngine data schema.

Things you may want to cover:
Project details can be found here: [Rales Engine](http://backend.turing.io/module3/projects/rails_engine)

* Ruby version
Ruby Version: 2.3.1
<br>
Rails Version: 5.0.0.1

* System dependencies
#### Setup

* Configuration
To run this project:

* Database creation
```
git clone [email protected]:epintozzi/rales_engine.git
cd rales_engine
bundle install
rake db:create db:migrate
rake populate_database:populate_all
```
Populating the database may take a few minutes, so please be patient.

* Database initialization
#### Testing

* How to run the test suite
This project uses RSpec for testing and can be run with the command `rspec`

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
This project also employs a Spec Harness. More info on the spec harness can be found here: [Rales Engine Spec Harness](https://github.com/turingschool/rales_engine_spec_harness)
8 changes: 8 additions & 0 deletions app/controllers/api/v1/customer_random_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::CustomerRandomController < ApplicationController

def show
random = Customer.all.count
render json: Customer.find(rand(random))
end

end
18 changes: 18 additions & 0 deletions app/controllers/api/v1/customer_search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Api::V1::CustomerSearchController < ApplicationController

def index
render json: Customer.where(customer_params)
end

def show
render json: Customer.find_by(customer_params)
end

private

def customer_params
params.permit(:id, :first_name, :last_name, :created_at, :updated_at)

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::Customers::FavoriteMerchantsController < ApplicationController

def index
customer = Customer.find(params[:customer_id])
render json: customer.favorite_merchant
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/customers/invoices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Customers::InvoicesController < ApplicationController

def index
render json: Customer.find(params[:customer_id]).invoices
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/customers/transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Customers::TransactionsController < ApplicationController

def index
render json: Customer.find(params[:customer_id]).transactions
end

end
11 changes: 11 additions & 0 deletions app/controllers/api/v1/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Api::V1::CustomersController < ApplicationController

def index
render json: Customer.all
end

def show
render json: Customer.find(params[:id])
end

end
8 changes: 8 additions & 0 deletions app/controllers/api/v1/invoice_item_random_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::InvoiceItemRandomController < ApplicationController

def show
random = InvoiceItem.all.count
render json: InvoiceItem.find(rand(random))
end

end
29 changes: 29 additions & 0 deletions app/controllers/api/v1/invoice_item_search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Api::V1::InvoiceItemSearchController < ApplicationController

def index
if params[:unit_price]
render json: InvoiceItem.where(unit_price: unit_price)
else
render json: InvoiceItem.where(invoice_item_params)
end
end

def show
if params[:unit_price]
render json: InvoiceItem.find_by(unit_price: unit_price)
else
render json: InvoiceItem.find_by(invoice_item_params)
end
end

private

def invoice_item_params
params.permit(:id, :quantity, :item_id, :invoice_id, :unit_price, :created_at, :updated_at)
end

def unit_price
(params[:unit_price].to_d * 100).to_i
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoice_items/invoices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::InvoiceItems::InvoicesController < ApplicationController

def index
render json: InvoiceItem.find(params[:invoice_item_id]).invoice
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoice_items/items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::InvoiceItems::ItemsController < ApplicationController

def index
render json: InvoiceItem.find(params[:invoice_item_id]).item
end

end
11 changes: 11 additions & 0 deletions app/controllers/api/v1/invoice_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Api::V1::InvoiceItemsController < ApplicationController

def index
render json: InvoiceItem.all
end

def show
render json: InvoiceItem.find(params[:id])
end

end
8 changes: 8 additions & 0 deletions app/controllers/api/v1/invoice_random_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::InvoiceRandomController < ApplicationController

def show
random = Invoice.all.count
render json: Invoice.find(rand(random))
end

end
17 changes: 17 additions & 0 deletions app/controllers/api/v1/invoice_search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Api::V1::InvoiceSearchController < ApplicationController

def index
render json: Invoice.where(invoice_params)
end

def show
render json: Invoice.find_by(invoice_params)
end

private

def invoice_params
params.permit(:id, :merchant_id, :customer_id, :status, :created_at, :updated_at)
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoices/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Invoices::CustomersController < ApplicationController

def index
render json: Invoice.find(params[:invoice_id]).customer
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoices/invoice_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Invoices::InvoiceItemsController < ApplicationController

def index
render json: Invoice.find(params[:invoice_id]).invoice_items
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoices/items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Invoices::ItemsController < ApplicationController

def index
render json: Invoice.find(params[:invoice_id]).items
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoices/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Invoices::MerchantsController < ApplicationController

def index
render json: Invoice.find(params[:invoice_id]).merchant
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/invoices/transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Invoices::TransactionsController < ApplicationController

def index
render json: Invoice.find(params[:invoice_id]).transactions
end

end
11 changes: 11 additions & 0 deletions app/controllers/api/v1/invoices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Api::V1::InvoicesController < ApplicationController

def index
render json: Invoice.all
end

def show
render json: Invoice.find(params[:id])
end

end
8 changes: 8 additions & 0 deletions app/controllers/api/v1/item_random_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::ItemRandomController < ApplicationController

def show
random = Item.all.count
render json: Item.find(rand(random))
end

end
29 changes: 29 additions & 0 deletions app/controllers/api/v1/item_search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Api::V1::ItemSearchController < ApplicationController

def index
if params[:unit_price]
render json: Item.where(unit_price: unit_price)
else
render json: Item.where(item_params)
end
end

def show
if params[:unit_price]
render json: Item.find_by(unit_price: unit_price)
else
render json: Item.find_by(item_params)
end
end

private

def item_params
params.permit(:id, :name, :description, :unit_price, :merchant_id, :created_at, :updated_at)
end

def unit_price
(params[:unit_price].to_d * 100).to_i
end

end
9 changes: 9 additions & 0 deletions app/controllers/api/v1/items/best_day_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Api::V1::Items::BestDayController < ApplicationController

def index
item = Item.find(params[:item_id])

render json: item.best_day, serializer: Api::V1::Items::BestDaySerializer
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/items/invoice_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Items::InvoiceItemsController < ApplicationController

def index
render json: Item.find(params[:item_id]).invoice_items
end

end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/items/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::Items::MerchantsController < ApplicationController

def index
render json: Item.find(params[:item_id]).merchant
end

end
Loading

0 comments on commit d699819

Please sign in to comment.