Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
402d90b
Rails new . --api project liftoff
SRBusiness Nov 6, 2017
6ca9f61
Adds controllers and routes
SRBusiness Nov 6, 2017
07f2382
Adds models for movies and customers
SRBusiness Nov 6, 2017
7b370b9
added relationships
VirtualLindsey Nov 6, 2017
7b7339f
Migration to add account credit to customer model
SRBusiness Nov 6, 2017
578b6b7
adds customer fixtures data and customers validations to model
SRBusiness Nov 6, 2017
ade4a2c
added basic validations for movies
VirtualLindsey Nov 6, 2017
1fcad33
Adds customer model tests for relationship and validates
SRBusiness Nov 6, 2017
2e75f0d
added more test cases for customers model test
SRBusiness Nov 6, 2017
bd8f17e
added validations to movie
VirtualLindsey Nov 6, 2017
b1fd10d
adds test controllers tests for customers controller index action
SRBusiness Nov 6, 2017
c63a6b5
fixing merge conflict
VirtualLindsey Nov 6, 2017
96ccb46
fixed merge conflict
VirtualLindsey Nov 6, 2017
dd94fe5
moved tests to test file
VirtualLindsey Nov 6, 2017
c97dba2
added some code to customers index controller action
SRBusiness Nov 6, 2017
d02f6d5
Merge branch 'master' of https://github.com/SRBusiness/VideoStoreAPI
SRBusiness Nov 6, 2017
dffdfb6
removed tests from movies model file
SRBusiness Nov 6, 2017
732ed33
added more yml data
SRBusiness Nov 7, 2017
9807828
added migration to change name of movies_count attribute in customer …
SRBusiness Nov 7, 2017
30180e7
Updates movies model tests and added fixture data
SRBusiness Nov 7, 2017
a99a7b1
add controller action and tests for movies index
SRBusiness Nov 7, 2017
e78984f
Updated error handling for movies show when a movie isn't found by th…
SRBusiness Nov 7, 2017
ceca1b7
adds migration for available inventory and then created a model custo…
SRBusiness Nov 7, 2017
05f5a05
removing tests from wrong file
VirtualLindsey Nov 7, 2017
a99ff26
removing tests from wrong file
VirtualLindsey Nov 7, 2017
8538e7b
DB updates and seed script updates
VirtualLindsey Nov 7, 2017
b118487
adding post command for making new movies
VirtualLindsey Nov 7, 2017
1b3b294
adding g
VirtualLindsey Nov 7, 2017
3ba27bb
adding CSRF line
VirtualLindsey Nov 7, 2017
1521a82
adding requirements for customer records
VirtualLindsey Nov 7, 2017
7bb99ee
fixing customer seed data
VirtualLindsey Nov 7, 2017
689444a
updates movies params method
SRBusiness Nov 7, 2017
055d8c5
fixing weird merge issue
VirtualLindsey Nov 7, 2017
44f42e0
Adds test for custom method in movie model and gets rid of some unnec…
SRBusiness Nov 7, 2017
be4867a
Merge branch 'master' of https://github.com/SRBusiness/VideoStoreAPI
SRBusiness Nov 7, 2017
df2620d
adding api tests
VirtualLindsey Nov 7, 2017
8dac95a
tweaks
VirtualLindsey Nov 7, 2017
55c30fb
wrong file
VirtualLindsey Nov 7, 2017
027ef90
Merge pull request #1 from SRBusiness/movieAPI
VirtualLindsey Nov 7, 2017
0077df3
Added a rentals controller
SRBusiness Nov 7, 2017
bfdc412
adding counter
Nov 7, 2017
0ac8547
Played with fixture data and rentals controller tests
SRBusiness Nov 7, 2017
d9afb26
adding tests to check errors
Nov 7, 2017
a88cc68
updating error checking
Nov 7, 2017
a6bada4
Merge pull request #2 from SRBusiness/movieControllerTests
VirtualLindsey Nov 7, 2017
99457ff
Refactored movies controller create tests to remove redundancy
SRBusiness Nov 7, 2017
ca24876
Merge branch 'master' of https://github.com/SRBusiness/VideoStoreAPI …
SRBusiness Nov 7, 2017
49d5741
Update rental model belongs to relationships, plural to singular
SRBusiness Nov 7, 2017
0f8dd3a
SRB - Adds first pass at rental model tests for relationships and val…
SRBusiness Nov 7, 2017
43e386e
Playing with checkout rentals controller action, something is up with…
SRBusiness Nov 7, 2017
eeba128
Reset seeds file to original format. DB migration to change both inve…
SRBusiness Nov 7, 2017
8ea87b1
More methodizing of rentals checkout controller action and test
SRBusiness Nov 8, 2017
193ab13
refactored and simplified checkout controller action, passes basic 3 …
SRBusiness Nov 8, 2017
257bf8e
updated routes so that checkin rental controller action passes smoke …
SRBusiness Nov 8, 2017
4d7b90a
adds custom method tests to movies model
SRBusiness Nov 8, 2017
942bfb4
adds custom method test for customers model
SRBusiness Nov 8, 2017
5e8588d
changes checkin route to update and stubbed out first test
SRBusiness Nov 8, 2017
eee3227
Adds migration that adds checkout_date and returned to rentals, plus …
SRBusiness Nov 8, 2017
9ec4769
refactored movie and customer methods to be more flexible so they can…
SRBusiness Nov 8, 2017
6b37150
updates rental controller update action and wrote tests for it
SRBusiness Nov 8, 2017
77d9275
updates checkin method to update customer and movie attributes after …
SRBusiness Nov 8, 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.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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

.byebug_history
58 changes: 58 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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.1.4'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.21.0'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# 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', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# 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]

gem 'jquery-turbolinks'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
end

group :development, :test do
gem 'pry-rails'
end

gem 'foundation-rails', '6.4.1.2'
gem 'awesome_print'
group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
end
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.1.4)
actionpack (= 5.1.4)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.4)
actionview (= 5.1.4)
activesupport (= 5.1.4)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.4)
activesupport (= 5.1.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.4)
activesupport (= 5.1.4)
globalid (>= 0.3.6)
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
arel (~> 8.0)
activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
arel (8.0.0)
awesome_print (1.8.0)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
better_errors (2.4.0)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
rack (>= 0.9.0)
binding_of_caller (0.7.3)
debug_inspector (>= 0.0.1)
builder (3.2.3)
byebug (9.1.0)
coderay (1.1.2)
concurrent-ruby (1.0.5)
crass (1.0.2)
debug_inspector (0.0.3)
erubi (1.7.0)
execjs (2.7.0)
ffi (1.9.18)
foundation-rails (6.4.1.2)
railties (>= 3.1.0)
sass (>= 3.3.0, < 3.5)
sprockets-es6 (>= 0.9.0)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.1)
concurrent-ruby (~> 1.0)
jquery-turbolinks (2.1.0)
railties (>= 3.1.0)
turbolinks
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.1.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
method_source (0.9.0)
mini_mime (0.1.4)
mini_portile2 (2.3.0)
minitest (5.10.3)
minitest-rails (3.0.0)
minitest (~> 5.8)
railties (~> 5.0)
minitest-reporters (1.1.18)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
nio4r (2.1.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
pg (0.21.0)
pry (0.11.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.6)
pry (>= 0.10.4)
puma (3.10.0)
rack (2.0.3)
rack-test (0.7.0)
rack (>= 1.0, < 3)
rails (5.1.4)
actioncable (= 5.1.4)
actionmailer (= 5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
activemodel (= 5.1.4)
activerecord (= 5.1.4)
activesupport (= 5.1.4)
bundler (>= 1.3.0)
railties (= 5.1.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.2.1)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
sass (3.4.25)
spring (2.0.2)
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.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.0)
thread_safe (0.3.6)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.3)
tzinfo (1.2.4)
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 (= 6.4.1.2)
jquery-turbolinks
listen (>= 3.0.5, < 3.2)
minitest-rails
minitest-reporters
pg (~> 0.21.0)
pry-rails
puma (~> 3.7)
rails (~> 5.1.4)
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data

BUNDLED WITH
1.15.4
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
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file added app/controllers/concerns/.keep
Empty file.
12 changes: 12 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CustomersController < ApplicationController
# protect_from_forgery with: :null_session

def index
customers = Customer.all

render(
json: customers.as_json(only: [:id, :name, :registered_at, :postal_code, :phone, :movies_checked_out_count]),
status: :ok
)
end
end
44 changes: 44 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class MoviesController < ApplicationController
# protect_from_forgery with: :null_session

def index
movies = Movie.all

render(
json: movies.as_json(only: [:id, :title, :release_date]),
status: :ok
)
end

def show
movie = Movie.find_by(id: params[:id])

if movie
render(
json: movie.as_json(only: [:title, :overview, :release_date, :inventory, :available_inventory]),
status: :ok
)
else
render(
json: {errors: {id: "Movie ID: #{params[:id]} not found"} },
status: :not_found
)
end
end

def create
movie = Movie.new(movie_params)
if movie.save
render json: {id: movie.id},
status: :ok
else
render json: {errors: movie.errors.messages},
status: :bad_request
end
end

private
def movie_params
params.permit(:title, :overview, :release_date, :inventory)
end
end
55 changes: 55 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class RentalsController < ApplicationController
def create
movie = Movie.find_by_id(rental_params[:movie_id])
customer = Customer.find_by_id(rental_params[:customer_id])

rental = Rental.new(movie: movie, customer: customer, due_date: rental_params[:due_date])

if rental.valid? # rental has all attributes
if movie.can_rent # the movie has enough available_inventory
rental.save
movie.update_available_inventory(-1)
customer.update_customer_movies(1)
render(
json: {id: movie.id},
status: :ok
)
else # movie doesn't have enough available_inventory
render json: {errors: {movie_id: "Movie ID: #{rental_params[:movie_id]} is out of stock and cannot be rented right now. Please try again later"} },
status: :bad_request
end
else # rental is missing attributes
render json: {errors: rental.errors.messages},
status: :bad_request
end
end

def update
movie = Movie.find_by_id(rental_params[:movie_id])
customer = Customer.find_by_id(rental_params[:customer_id])
rental = Rental.find_by(movie: movie, customer: customer)

if rental # rental exists
if rental.returned # rental has already been returned
render json: {errors: {movie_id: "Movie ID: #{rental_params[:movie_id]} was already returned"} },
status: :bad_request
else # rental not returned yet
rental.update(returned: true)
movie.update_available_inventory(1)
customer.update_customer_movies(-1)
render(
json: {id: params[:movie_id]},
status: :ok
)
end
else # rental does not exist based on combo of movie and customer id
render json: {errors: "Rental does not exist."},
status: :bad_request
end
end

private
def rental_params
params.permit(:movie_id, :customer_id, :due_date)
end
end
Loading