Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
5fe5fd3
made new empty api app
ssamant May 9, 2017
d01445a
Merge pull request #1 from ssamant/generate_new_api_app
ssamant May 9, 2017
b5bdffa
baseline with test route
ssamant May 9, 2017
8d5c69e
Merge pull request #2 from ssamant/baseline
ssamant May 9, 2017
056e985
added gems needed for testing and error views
botrethewey May 9, 2017
80e3529
Merge pull request #3 from ssamant/add-gems
botrethewey May 9, 2017
33b86fa
generated models for movies and customers
botrethewey May 9, 2017
a602dea
Merge pull request #4 from ssamant/add-models
botrethewey May 9, 2017
2cebec7
updated gemfile.lock
botrethewey May 9, 2017
2117324
added coverage to gitignore
ssamant May 9, 2017
196cf06
Merge branch 'master' of https://github.com/ssamant/VideoStoreAPI
ssamant May 9, 2017
3886f7d
Merge branch 'master' of https://github.com/ssamant/VideoStoreAPI
botrethewey May 9, 2017
5a031f2
schema created
botrethewey May 9, 2017
23a3ada
schema file
ssamant May 9, 2017
bee7a24
Merge branch 'master' of https://github.com/ssamant/VideoStoreAPI
ssamant May 9, 2017
732afca
added default value for account credit in Customer model
ssamant May 9, 2017
cb26563
validations for customer and movie models
ssamant May 9, 2017
8abd0ab
Merge pull request #5 from ssamant/modify_models
ssamant May 9, 2017
fb97a18
trying to fix regex in customer model
ssamant May 9, 2017
7ca8c02
adjusting regex
ssamant May 9, 2017
91ccd40
tests for customer model
ssamant May 9, 2017
a4a0e95
tests for Movie model
ssamant May 9, 2017
c40ab78
Merge pull request #6 from ssamant/model_tests
ssamant May 9, 2017
563e704
initially generted controllers for customers and movies
botrethewey May 9, 2017
638714c
update routes
botrethewey May 9, 2017
7be22ef
added controller tests for customers
botrethewey May 9, 2017
de6fe7a
update customers controller
botrethewey May 9, 2017
8ef5f20
Merge pull request #7 from ssamant/add-controllers
botrethewey May 9, 2017
121b2c1
movie controller tests and controller index and show actions
ssamant May 10, 2017
df86273
test for custom method available_inventory and method
ssamant May 10, 2017
ff507d5
Merge pull request #8 from ssamant/movie_controller_testing
ssamant May 10, 2017
7847e96
update error handling for movie show action
botrethewey May 10, 2017
221d35e
Merge pull request #9 from ssamant/update-error-handling
botrethewey May 10, 2017
2d37a9e
wip: added custom method to customer model
botrethewey May 10, 2017
0785c12
Merge pull request #10 from ssamant/add-custom-method-to-customer
botrethewey May 10, 2017
4cebdb2
finishing test and controller action for movie count
ssamant May 10, 2017
fa4b7cd
Merge pull request #11 from ssamant/customer_movie_count
ssamant May 10, 2017
7e4c786
added routes for rental optionals
ssamant May 10, 2017
2f7cc15
created rental model
ssamant May 10, 2017
da6c2b1
controller for Rentals
ssamant May 10, 2017
4e4757f
started model tests for rental
ssamant May 10, 2017
3537ec2
testing rental model validations for due date
ssamant May 10, 2017
a251452
Merge pull request #12 from ssamant/check-out-rental
ssamant May 10, 2017
4e447f9
db:reset after pull
botrethewey May 11, 2017
39cf376
removed extra unused defult routes
botrethewey May 11, 2017
4530b4d
added entity relationship test
botrethewey May 11, 2017
4dbe4e9
added simple cov
botrethewey May 11, 2017
f431b51
clean up model file
botrethewey May 11, 2017
48957ad
update rental model test
botrethewey May 11, 2017
740928d
Merge pull request #13 from ssamant/bt-update-rentals-test
botrethewey May 11, 2017
44848e1
added some tests
botrethewey May 11, 2017
d31ed5b
Merge pull request #14 from ssamant/add-rental-controller
botrethewey May 11, 2017
0cf9d41
wrote controller action for rental create and updated tests
ssamant May 11, 2017
e34603e
Merge pull request #15 from ssamant/rental-create-controller
ssamant May 11, 2017
d7394fa
updated tests and controller logic
botrethewey May 12, 2017
2097e8b
Merge pull request #16 from ssamant/update-rental-logic
botrethewey May 12, 2017
b2b9bd5
logic and tests for Movie model method available inventory
ssamant May 12, 2017
8245341
tests for custom method check_availability in rental model
ssamant May 12, 2017
ff405d5
finised testing for rental model custom method
ssamant May 12, 2017
b72001a
Merge pull request #17 from ssamant/rental_logic_inventory
ssamant May 12, 2017
e442f2e
fix typo in movie controllers test
botrethewey May 12, 2017
70ee7ef
added tests for the rentals custom method in model
botrethewey May 12, 2017
2b3de18
Merge pull request #18 from ssamant/update-rental-controller-test
botrethewey May 12, 2017
510a49d
fixed error message in rental model test
botrethewey May 12, 2017
029a914
updated logic on movies_checked_out_count method
botrethewey May 12, 2017
0f368f0
updated tests for the custom method
botrethewey May 12, 2017
968032d
Merge pull request #19 from ssamant/update-customer-custom-method
botrethewey May 12, 2017
bf6306b
TDD! wrote controller tests for Rental update action
ssamant May 12, 2017
d19069c
tests for update action in Rental
ssamant May 12, 2017
8ad3f29
WIP overdue action in rental controller
ssamant May 12, 2017
bb987ed
Merge pull request #20 from ssamant/overdue_action
ssamant May 12, 2017
79cd476
hash to give to json in overdue action with all the required fields
ssamant May 13, 2017
656104e
WIP changed error message in check_inventory method to give estimated…
ssamant May 13, 2017
df6b2c1
Merge pull request #21 from ssamant/sandbox_overdue
ssamant May 13, 2017
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
Binary file added .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore Byebug command history file.
.byebug_history
/coverage/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also ignore that pesky .DS_Store

56 changes: 56 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
source 'https://rubygems.org'

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh that's why some of this looks weird to me, shiny new rails! ✨ (we used 4.2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same reaction!

# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end

group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :development do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you have two 'group :development do' sections - you could combine them to clean up the Gemfile.

gem 'better_errors'
gem 'binding_of_caller'
gem 'pry-rails'
end

group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
gem 'simplecov'
end

gem 'awesome_print'
gem 'foundation-rails'
187 changes: 187 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.0.2)
actionpack (= 5.0.2)
nio4r (>= 1.2, < 3.0)
websocket-driver (~> 0.6.1)
actionmailer (5.0.2)
actionpack (= 5.0.2)
actionview (= 5.0.2)
activejob (= 5.0.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.0.2)
actionview (= 5.0.2)
activesupport (= 5.0.2)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.0.2)
activesupport (= 5.0.2)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.0.2)
activesupport (= 5.0.2)
globalid (>= 0.3.6)
activemodel (5.0.2)
activesupport (= 5.0.2)
activerecord (5.0.2)
activemodel (= 5.0.2)
activesupport (= 5.0.2)
arel (~> 7.0)
activesupport (5.0.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
arel (7.1.4)
awesome_print (1.7.0)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.3)
byebug (9.0.6)
coderay (1.1.1)
concurrent-ruby (1.0.5)
debug_inspector (0.0.2)
docile (1.1.5)
erubis (2.7.0)
execjs (2.7.0)
ffi (1.9.18)
foundation-rails (6.3.1.0)
railties (>= 3.1.0)
sass (>= 3.3.0, < 3.5)
sprockets-es6 (>= 0.9.0)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.1)
json (2.0.2)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.5)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
minitest-rails (3.0.0)
minitest (~> 5.8)
railties (~> 5.0)
minitest-reporters (1.1.14)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
nio4r (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
pg (0.20.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.6)
pry (>= 0.10.4)
puma (3.8.2)
rack (2.0.2)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.2)
actioncable (= 5.0.2)
actionmailer (= 5.0.2)
actionpack (= 5.0.2)
actionview (= 5.0.2)
activejob (= 5.0.2)
activemodel (= 5.0.2)
activerecord (= 5.0.2)
activesupport (= 5.0.2)
bundler (>= 1.3.0, < 2.0)
railties (= 5.0.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.2)
activesupport (>= 4.2.0, < 6.0)
nokogiri (~> 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.0.2)
actionpack (= 5.0.2)
activesupport (= 5.0.2)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
ruby-progressbar (1.8.1)
sass (3.4.23)
simplecov (0.13.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (2.0.1)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-es6 (0.9.2)
babel-source (>= 5.8.11)
babel-transpiler
sprockets (>= 3.0.0)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.4)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)

PLATFORMS
ruby

DEPENDENCIES
awesome_print
better_errors
binding_of_caller
byebug
foundation-rails
listen (~> 3.0.5)
minitest-rails
minitest-reporters
pg (~> 0.18)
pry-rails
puma (~> 3.0)
rails (~> 5.0.2)
simplecov
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data

BUNDLED WITH
1.14.6
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
4 changes: 4 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::API
def index
render :json => { testing: "it works!!"}
end
end
Empty file added app/controllers/concerns/.keep
Empty file.
6 changes: 6 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CustomersController < ApplicationController
def index
customers = Customer.all
render json: customers.as_json(only: [:id, :name, :registered_at, :postal_code, :phone], methods: :movies_checked_out_count), status: :ok
end
end
15 changes: 15 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MoviesController < ApplicationController
def index
movies = Movie.all
render json: movies.as_json(only: [:title, :release_date]), status: :ok
end

def show
movie = Movie.find_by(title: params[:title])
if movie
render json: movie.as_json(except: [:created_at, :updated_at, :id], methods: :available_inventory), status: :ok
else
render json: {"errors" => {"title" => "Movie '#{params[:title]}' not found"}}, status: :not_found
end
end
end
67 changes: 67 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class RentalsController < ApplicationController
def create
rental_info = rental_params
rental_info[:title] = params[:title]
rental = Rental.new(rental_info)
if rental.save
render status: :ok, json: {id: rental.id}
else
render status: :bad_request, json: { errors: rental.errors.messages }
end
end

def update
movie = Movie.find_by(title: params[:title] )
rental = Rental.find_by(movie_id: movie.id, customer_id: rental_params[:customer_id], returned: false)
if rental
rental.returned = true
if rental.save
render status: :ok, json: { movie_returned: true }
end
elsif Rental.find_by(movie_id: movie.id, customer_id: rental_params[:customer_id], returned: true)
render status: :bad_request, json: { errors: { check_in: "Customer has already checked in this movie"}}
else
render status: :bad_request, json: { errors: { check_in: "Cannot find this rental"} }
end
end

def overdue
#what is the syntax for a conditional for due date?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to clean up comments! 🔍

rentals = Rental.where("returned = ? AND due_date <= ?", false, Date.current)
if rentals
#array of customer ids for customers who have overdue rentals
customer_ids = rentals.map { |rental| rental.customer_id }

overdue_rentals = []
customer_ids.each do |id|
customer = Customer.find_by_id(id)
hash = Hash.new
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency you could do {} (since you do [] for a new array)...but this is me completely nitpicking bc you did such a great job 😁

hash[:name] = customer.name
hash[:customer_id] = id
hash[:postal_code] = customer.postal_code

rentals = []
customer.rentals.each do |rental|
rental_hash = Hash.new
rental_hash[:title] = Movie.find_by_id(rental.movie_id).title
rental_hash[:checkout_date] = rental.created_at.to_date
rental_hash[:due_date] = rental.due_date
rentals << rental_hash
end
hash[:rentals] = rentals
overdue_rentals << hash
end
render status: :ok, json: overdue_rentals.as_json
else
render status: :bad_request, json: { overdue: "There are no overdue rentals" }
end

end

private

def rental_params
params.require(:rental).permit(:due_date, :customer_id)
end

end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file added app/models/concerns/.keep
Empty file.
Loading