Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2b3756e
new rails app created with ERD diagram
TamikoT May 9, 2017
99c1b9e
/zomg route is rendering success message
May 9, 2017
04e4017
pseudocode for routes
TamikoT May 9, 2017
3873aef
notes for routes
TamikoT May 9, 2017
0781017
Merge branch 'master' of https://github.com/sahanamurthy/VideoStoreAPI
TamikoT May 9, 2017
ffb0c09
Created customer and rental models
May 9, 2017
881c2be
create movie model
TamikoT May 9, 2017
951ca70
Merge branch 'moviemodel'
TamikoT May 9, 2017
ebb97e3
Migrated rental and customer models
May 9, 2017
5ebd6a5
Merge branch 'master' of https://github.com/sahanamurthy/VideoStoreAPI
May 9, 2017
b9a842a
Seeded customers info into db
May 9, 2017
c10cb78
schema changed from db:migrate
TamikoT May 9, 2017
be17996
TDD: movie tests outline as it statements
TamikoT May 9, 2017
626d6a8
merge changes to migrations
TamikoT May 9, 2017
09af998
Added has_many :rentals relationship
May 9, 2017
51c12d9
Created some tests (passing) for customer model
May 10, 2017
2cf4432
movies test outlined
TamikoT May 10, 2017
2572c69
Merge branch 'moviemodel'
TamikoT May 10, 2017
889f6da
installed serializer gem
May 10, 2017
2a4ffa0
Created serializers for movie and customer
May 10, 2017
5808b90
created moviescontroller
TamikoT May 10, 2017
cd4daba
All customer model tests passing
May 10, 2017
109a526
Merge branch 'master' of https://github.com/sahanamurthy/VideoStoreAPI
May 10, 2017
ee65fcb
Customer controller
May 10, 2017
9942481
add model tests for validations
TamikoT May 10, 2017
fb692ff
added movies_checked_out to customers
TamikoT May 10, 2017
31cbfcd
TDD add index test and route
TamikoT May 10, 2017
4402da5
TDD tests for JSON for customers#index
TamikoT May 10, 2017
5b0ad26
Merge branch 'controller-tests'
TamikoT May 10, 2017
0e35ee9
TDD change serializer to pass test
TamikoT May 10, 2017
15dcfcc
Changed movies_checked_out column to movies_checked_out_count
May 10, 2017
176a595
Merge branch 'master' of https://github.com/sahanamurthy/VideoStoreAP…
TamikoT May 10, 2017
6475a7b
changed syntax in routes
May 10, 2017
eee0a48
Merge branch 'master' of https://github.com/sahanamurthy/VideoStoreAPI
May 10, 2017
1a2cb50
Movies controller index method completed and index method tests passing
May 10, 2017
c3b5177
TDD add specs and validations for Movies
TamikoT May 12, 2017
5c4a22b
Merge branch 'master' of https://github.com/sahanamurthy/VideoStoreAP…
TamikoT May 12, 2017
a109687
Some tests for movies show method passing
May 12, 2017
843bcb6
added available_inventory to movies table
May 12, 2017
2d40f5c
reset default value of available_inventory in movies
May 12, 2017
2c4de7e
All smoke tests passinggit add . Hooraygit add .
May 12, 2017
f20b578
Add test for no customer
TamikoT May 12, 2017
f5f4cb9
Merge branch 'error'
TamikoT May 12, 2017
d6f8e7a
JSON responses changed to match the project requirements. All smoke t…
May 12, 2017
d919d24
Wrote a movie edge test
May 12, 2017
6919096
fixed success case test for movies show method
May 12, 2017
4cea723
fixed 204 no content movie show test
May 12, 2017
1bafde5
finished tests for movies show
May 12, 2017
f230357
add rentals columns
TamikoT May 12, 2017
cfed605
FINISHED OPTIONAL CHECKOUT FEATURE YAYgit add .
May 12, 2017
27741d1
Passing test for movie set_available_inventory method
May 12, 2017
22af051
Movies controller tests check with Charlesgit add .
May 13, 2017
5c838d7
we're learning thingsgit add . ! on a friday evening. with some wine
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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
53 changes: 53 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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'
gem 'active_model_serializers', '~> 0.10.0'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'pry-rails'
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 'foundation-rails'
end

group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
end
182 changes: 182 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
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)
active_model_serializers (0.10.6)
actionpack (>= 4.1, < 6)
activemodel (>= 4.1, < 6)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.2)
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)
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)
case_transform (0.2)
activesupport
coderay (1.1.1)
concurrent-ruby (1.0.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)
jsonapi-renderer (0.1.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.2)
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)
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
active_model_serializers (~> 0.10.0)
better_errors
byebug
foundation-rails
listen (~> 3.0.5)
minitest-rails
minitest-reporters
pg (~> 0.18)
pry-rails
puma (~> 3.0)
rails (~> 5.0.2)
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
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.
8 changes: 8 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CustomersController < ApplicationController

def index
customers = Customer.all
render :json => customers, status: :ok
end

end
30 changes: 30 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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, status: :ok
else
render :json => movie, status: :not_found
end
end

def checkout
movie = Movie.find_by(title: params[:title])
movie.available_inventory -= 1
movie.save

customer = Customer.find_by(id: params[:customer_id])
customer.movies_checked_out_count += 1
customer.save

rental = Rental.create(customer_id: customer.id, due_date: params[:due_date], movie_id: movie.id)
render :json => rental, status: :ok
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.
8 changes: 8 additions & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Customer < ApplicationRecord
has_many :rentals
validates :name, presence: true
validates :phone, presence: true
validates :registered_at, presence: true
validates :postal_code, length: { is: 5 }, allow_nil: true, allow_blank: true
validates :account_credit, numericality: {greater_than_or_equal_to: 0}
end
13 changes: 13 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Movie < ApplicationRecord
after_initialize :set_available_inventory

has_many :rentals

validates :title, presence: true, uniqueness: true
validates :inventory, numericality: { only_integer: true, greater_than_or_equal_to: 0 }# by default does not allow nil

def set_available_inventory
self.available_inventory ||= self.inventory
end

end
4 changes: 4 additions & 0 deletions app/models/rental.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Rental < ApplicationRecord
belongs_to :movie
belongs_to :customer
end
3 changes: 3 additions & 0 deletions app/serializers/customer_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CustomerSerializer < ActiveModel::Serializer
attributes :id, :name, :registered_at, :postal_code, :phone, :movies_checked_out_count
end
3 changes: 3 additions & 0 deletions app/serializers/movie_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class MovieSerializer < ActiveModel::Serializer
attributes :title, :overview, :release_date, :inventory, :available_inventory
end
13 changes: 13 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>

<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
3 changes: 3 additions & 0 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
9 changes: 9 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
Loading