Skip to content

Haby and Kelly Video API #11

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

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5a435a7
Baseline setup of controllers and models
kellysouza May 9, 2017
da08a3d
zomg it works
kellysouza May 9, 2017
e8487f1
Added two additional columns to customer model
habypsow May 9, 2017
3895334
Wrote index method for movies controller, as well as tests
habypsow May 9, 2017
58b2457
Index tests for movies controller
habypsow May 9, 2017
5304f18
Wrote show method for movies controller
habypsow May 9, 2017
0aa5f15
Adds testing for create method in movies controller
kellysouza May 9, 2017
dfd6828
Writing tests for customer controller
habypsow May 9, 2017
fe3619a
Writing create method for customer model
habypsow May 9, 2017
8893f40
Added column to customers model, movies_checked_out_count
habypsow May 9, 2017
1bdc89c
Wrote negative tests for customer validations
habypsow May 9, 2017
365afe5
Added test to movies model
habypsow May 9, 2017
bbb5480
Passes smoke test with small changes
kellysouza May 9, 2017
6ff9d2a
Added rentals controller and model, as well as references
habypsow May 10, 2017
2a5131d
adds checkout_movie method
kellysouza May 10, 2017
b39b052
Added fixtures, for rentals, and set default value of 0 to movies_che…
habypsow May 10, 2017
4bbbc4e
Working on create test in rentals
habypsow May 10, 2017
d6f1733
Adds find available_inventory method
kellysouza May 12, 2017
2949c97
Rentals controller testing
habypsow May 12, 2017
ff4164b
Merge branch 'rentals'
habypsow May 12, 2017
2792652
Merge branch 'rentals' of https://github.com/kellysouza/VideoStoreAPI…
habypsow May 12, 2017
d7fd259
Adds to checkout and available inventory method
kellysouza May 12, 2017
e9444d3
Merge branch 'master' of https://github.com/kellysouza/VideoStoreAPI
kellysouza May 12, 2017
410160d
Create a rental test passing
habypsow May 12, 2017
df10e68
Adds error for movie not found during checkout
kellysouza May 12, 2017
b8a88cb
Fixing broken tests in movies controller tests
habypsow May 12, 2017
d30dadb
Working on tests in movies controller tests
habypsow May 12, 2017
1d6b3ed
Tests for create movie working in movies controller tests
habypsow May 12, 2017
353c351
Writing tests for checkout movie
habypsow May 12, 2017
5cc9abd
Writing overdue method
habypsow May 12, 2017
e6bbc41
Writing json render for overdue mehtod
habypsow May 12, 2017
ee29e2b
Working on overdue message, returns overdue, needs error handling
kellysouza May 12, 2017
734c83b
decrements available inventory when movie checked out.
kellysouza May 12, 2017
df21691
Added customer checked out count
habypsow May 12, 2017
c49e2a3
increments movies_checked_out_count for movie checkout method
kellysouza May 12, 2017
0b02837
Fixed rentals_controller merge conflict
kellysouza May 12, 2017
849bad7
Increment and decrement mcoc and avail inventory on checkin and checkout
kellysouza May 12, 2017
390e745
adding conditionals to checkin method
kellysouza May 13, 2017
bfcc582
Rental checking now has error handling and new checkin date column
kellysouza May 13, 2017
b9678a3
Adds Adjust Inventory Method
kellysouza May 13, 2017
aa2e321
Created model methods to adjust inventory for customer and movie
kellysouza 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
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/
55 changes: 55 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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'
# 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
gem 'better_errors'
gem 'pry-rails'
end

gem 'awesome_print'
gem 'foundation-rails'
group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
gem 'minitest-skip', '~> 0.0.1'
gem 'simplecov', :require => false
end
186 changes: 186 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
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)
builder (3.2.3)
byebug (9.0.6)
coderay (1.1.1)
concurrent-ruby (1.0.5)
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.1.0)
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
minitest-skip (0.0.1)
minitest (~> 5.0)
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.14.1)
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
byebug
foundation-rails
listen (~> 3.0.5)
minitest-rails
minitest-reporters
minitest-skip (~> 0.0.1)
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
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationController < ActionController::API

# def index
# render json:{ zomg: "it works!" }
# end

end
Empty file added app/controllers/concerns/.keep
Empty file.
23 changes: 23 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class CustomersController < ApplicationController

def index
customers = Customer.all
render json: customers.as_json(only: [:id, :name, :address, :city, :state, :postal_code, :phone, :registered_at, :account_credit, :movies_checked_out_count])
end

def create
customer = Customer.new(customer_params)
if customer.save
render status: :ok, json: { id: customer.id}
else
render status: :bad_request, json: { errors: customer.errors.messages }
end
end


private

def customer_params
params.require(:customer).permit(:name, :address, :city, :state, :postal_code, :phone, :registered_at, :account_credit, :movies_checked_out_count)
end
end
37 changes: 37 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class MoviesController < ApplicationController

def index
movies = Movie.all
render json: movies.as_json(only: [:title, :overview, :release_date, :inventory, :available_inventory])
end

def show
movie = Movie.find_by(title: params[:title])
if movie
render json: movie.as_json(only: [:title, :overview, :release_date, :inventory, :available_inventory]), status: :ok
else
render json:{ nothing: true }, status: :not_found
end
end


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



private


def movie_params
params.permit(:title, :overview, :release_date, :inventory, :available_inventory)
end
end
Loading