Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
3e2f010
create rail project
jessiezhang2017 Nov 5, 2018
b7d8599
Update README.md
JaneEdwMcN Nov 5, 2018
e279db6
Update README.md
JaneEdwMcN Nov 5, 2018
d99a93f
Update README.md
JaneEdwMcN Nov 5, 2018
0c6d553
created controllers
jessiezhang2017 Nov 5, 2018
c8a105e
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
jessiezhang2017 Nov 5, 2018
e8c9490
added models for Customer, Rental, and Movie
JaneEdwMcN Nov 5, 2018
093b182
added relationships to models
JaneEdwMcN Nov 5, 2018
ca569f2
moved foregin key from movie to rental
jessiezhang2017 Nov 5, 2018
7d1e929
added markdown file for pseudo-coded routes
JaneEdwMcN Nov 5, 2018
2326359
added pseudo code routes for movies, check-in, check-out
JaneEdwMcN Nov 5, 2018
c70d3f2
complete the pseudo code routes
jessiezhang2017 Nov 5, 2018
fec0a7a
created routes
JaneEdwMcN Nov 5, 2018
b340e8a
created routes
JaneEdwMcN Nov 5, 2018
6928129
added failed zomg route and method
JaneEdwMcN Nov 5, 2018
d7e263f
fixed the zomg action in controller
jessiezhang2017 Nov 5, 2018
62b177d
remove string field fm customer, added fixtures for test
jessiezhang2017 Nov 5, 2018
351aaa0
added validations to rentals and customers
JaneEdwMcN Nov 5, 2018
53af761
added relationship tests and fixed line in test_helper.rb
JaneEdwMcN Nov 5, 2018
7c65d13
added more tests for rental model
JaneEdwMcN Nov 5, 2018
e9d4a1f
added customer model tests
JaneEdwMcN Nov 5, 2018
78fcf90
set up default values
jessiezhang2017 Nov 5, 2018
3d7c7c2
updated the movie model test
jessiezhang2017 Nov 6, 2018
7ad8bb1
added customers API call and index method and tests for controller
JaneEdwMcN Nov 6, 2018
08210b0
added test for movie index action
jessiezhang2017 Nov 6, 2018
b084c8d
resolve merge conflect
jessiezhang2017 Nov 6, 2018
c672b43
added movie create and tests
JaneEdwMcN Nov 6, 2018
165fe0a
fixed merge conflicts
JaneEdwMcN Nov 6, 2018
f319b0f
added test for movie show action
jessiezhang2017 Nov 6, 2018
ed80269
made create pass smoke test
JaneEdwMcN Nov 6, 2018
d765aef
updated the show test
jessiezhang2017 Nov 6, 2018
db44ecb
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
jessiezhang2017 Nov 6, 2018
9c6febe
fixed controller to pass smoke tests and updated controller tests
JaneEdwMcN Nov 6, 2018
508fcfc
added check_in method to rentals controller
JaneEdwMcN Nov 6, 2018
da10c2d
added the rantal checkout method
jessiezhang2017 Nov 6, 2018
d5efe23
added checkout method
jessiezhang2017 Nov 6, 2018
15face8
resolved conflict
JaneEdwMcN Nov 6, 2018
65f19e2
conflict
JaneEdwMcN Nov 6, 2018
c9e2133
readded Jane's check_in method
JaneEdwMcN Nov 6, 2018
cd3eb06
added available inventory column and updated seeds
JaneEdwMcN Nov 6, 2018
935aa2e
udpated the available inventory column for movie
jessiezhang2017 Nov 6, 2018
0a25d68
updated tests and methods to use available_inventory
JaneEdwMcN Nov 6, 2018
419e3b6
Merge branch 'adjust_code_to_have_inventory_and_available_inventory'
JaneEdwMcN Nov 6, 2018
12aaeb2
added optional sort and pagination fields to customers
JaneEdwMcN Nov 6, 2018
80d6938
udpated checkout action
jessiezhang2017 Nov 6, 2018
c4d8655
Merge branch 'checkout2'
jessiezhang2017 Nov 6, 2018
94691c0
added rental seed data
JaneEdwMcN Nov 7, 2018
b2374e3
added sort and paginate to movie controller
jessiezhang2017 Nov 7, 2018
f384354
almost completed overdue method. Pulling in Jesse's changes to implem…
JaneEdwMcN Nov 7, 2018
0016d71
Merge branch 'optional_rental_overdue_route_and_method'
JaneEdwMcN Nov 7, 2018
a588081
move check sort method to model
jessiezhang2017 Nov 7, 2018
107b09d
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
jessiezhang2017 Nov 7, 2018
f088dc7
added more rental seed data
JaneEdwMcN Nov 7, 2018
e9692a8
added controller action for listing customers of a movie
jessiezhang2017 Nov 7, 2018
3e903e6
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
JaneEdwMcN Nov 7, 2018
be229b0
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
jessiezhang2017 Nov 7, 2018
0453f4f
moved some check-in and check-out logic to the Rental model
JaneEdwMcN Nov 7, 2018
ead5adf
added check_in check_out methods to Customer and Movie model to seper…
JaneEdwMcN Nov 7, 2018
7fcbe89
finished overdue method with error messages for invalid params
JaneEdwMcN Nov 7, 2018
ec815ba
fixed merge conflicts in customer.rb and movie.rb
JaneEdwMcN Nov 7, 2018
11e15e1
current_check_out_customers
jessiezhang2017 Nov 7, 2018
e5d23fb
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
jessiezhang2017 Nov 7, 2018
6c3e3f5
added helper methods to clean up code
JaneEdwMcN Nov 8, 2018
aedb8ab
moved helper methods to Rental model
JaneEdwMcN Nov 8, 2018
7696d6b
moved a comment down one line
JaneEdwMcN Nov 8, 2018
83abe54
deleted an empty line
JaneEdwMcN Nov 8, 2018
36aeb19
added current method to customers to list the movies a customer curre…
JaneEdwMcN Nov 8, 2018
2942214
completed current method that lists the movies a customer has checked…
JaneEdwMcN Nov 8, 2018
e1c2758
added find_customer method to Customers controller
JaneEdwMcN Nov 8, 2018
a556e1c
udpated the current customer method
jessiezhang2017 Nov 8, 2018
36121f1
merge conflict
jessiezhang2017 Nov 8, 2018
4efd4be
fixed find_customer method
JaneEdwMcN Nov 8, 2018
abc71c7
Merge branch 'see_about_moving_some_logic_to_models'
JaneEdwMcN Nov 8, 2018
05f42b3
udpated current customer action in movie
jessiezhang2017 Nov 8, 2018
20e18b1
rewrote current and history (customers) with new logic
JaneEdwMcN Nov 8, 2018
c2c0a01
updated the current customer action in movie
jessiezhang2017 Nov 8, 2018
3f7df37
Merge branch 'master' of https://github.com/jessiezhang2017/VideoStor…
jessiezhang2017 Nov 8, 2018
e99f27d
changed the current and history action for movie
jessiezhang2017 Nov 8, 2018
25fe8e9
moved helper methods to Customer model for index, current, and history
JaneEdwMcN Nov 8, 2018
b03bd8c
readded missing methods
JaneEdwMcN Nov 8, 2018
cf8ea98
added .class to methods to fix errors
JaneEdwMcN Nov 8, 2018
67a1c67
added Rental model tests
JaneEdwMcN Nov 9, 2018
233792e
set up tests for Rentals controller
JaneEdwMcN Nov 9, 2018
d3d9fa9
updated current and history action for movie
jessiezhang2017 Nov 9, 2018
641ab56
resolve conflict
jessiezhang2017 Nov 9, 2018
a49c79e
dry movie controller actions
jessiezhang2017 Nov 9, 2018
8f42492
added movie controller test & model test
jessiezhang2017 Nov 9, 2018
affccce
adding rental tests
JaneEdwMcN Nov 9, 2018
c3e2bd0
fixed merge conflict in rental fixtures
JaneEdwMcN Nov 9, 2018
aac2316
completed rental controller tests
JaneEdwMcN Nov 9, 2018
c08cd2a
deleted a couple unused lines
JaneEdwMcN Nov 9, 2018
acdcc04
completed customer controller tests
JaneEdwMcN Nov 9, 2018
82dc121
fixed test
JaneEdwMcN Nov 9, 2018
ffb565f
fixed the test
jessiezhang2017 Nov 9, 2018
ec14516
Merge branch 'test5'
jessiezhang2017 Nov 9, 2018
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
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 uploaded files in development
/storage/*
!/storage/.keep

.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.4.1
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) { |repo| "https://github.com/#{repo}.git" }

ruby '2.4.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# 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', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

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

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

# 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]

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

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

gem 'will_paginate', '~> 3.1.0'
171 changes: 171 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.1)
actionpack (= 5.2.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.1)
actionview (= 5.2.1)
activesupport (= 5.2.1)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.1)
activesupport (= 5.2.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.1)
activesupport (= 5.2.1)
globalid (>= 0.3.6)
activemodel (5.2.1)
activesupport (= 5.2.1)
activerecord (5.2.1)
activemodel (= 5.2.1)
activesupport (= 5.2.1)
arel (>= 9.0)
activestorage (5.2.1)
actionpack (= 5.2.1)
activerecord (= 5.2.1)
marcel (~> 0.3.1)
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
arel (9.0.0)
bootsnap (1.3.2)
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
coderay (1.1.2)
concurrent-ruby (1.1.1)
crass (1.0.4)
erubi (1.7.1)
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.1)
mimemagic (0.3.2)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
minitest-rails (3.0.0)
minitest (~> 5.8)
railties (~> 5.0)
minitest-reporters (1.3.5)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
msgpack (1.2.4)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
pg (1.1.3)
pry (0.12.0)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.6)
pry (>= 0.10.4)
puma (3.12.0)
rack (2.0.5)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.1)
actioncable (= 5.2.1)
actionmailer (= 5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
activemodel (= 5.2.1)
activerecord (= 5.2.1)
activestorage (= 5.2.1)
activesupport (= 5.2.1)
bundler (>= 1.3.0)
railties (= 5.2.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
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.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will_paginate (3.1.6)

PLATFORMS
ruby

DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
listen (>= 3.0.5, < 3.2)
minitest-rails
minitest-reporters
pg (>= 0.18, < 2.0)
pry-rails
puma (~> 3.11)
rails (~> 5.2.1)
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data
will_paginate (~> 3.1.0)

RUBY VERSION
ruby 2.4.1p111

BUNDLED WITH
1.17.1
9 changes: 9 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
guard :minitest, autorun: false, spring: true do
watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' }
watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
watch(%r{^test/.+_test.rb$})
watch(%r{^test/test_helper.rb$}) { 'test' }
end
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Request body:
| `customer_id` | integer | ID of the customer checking in this film
| `movie_id` | integer | ID of the movie to be checked in

## Optional Enhancements
<!--- ## Optional Enhancements
These really are **optional** - if you've gotten here and you have time left, that means you're moving speedy fast!

### Query Parameters
Expand Down Expand Up @@ -300,8 +300,7 @@ URI parameters:
Fields to return:
- `title`
- `checkout_date`
- `due_date`

- `due_date` --->

## Reference
- [Postman on Environments](https://www.getpostman.com/docs/environments)
Expand Down
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.
65 changes: 65 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class CustomersController < ApplicationController
before_action :find_customer, only: [:history, :current]

def index
customers = Customer.all
customers = Customer.paginate_check(customers, cust_params["p"], cust_params["n"])
customers = Customer.sort_check(customers, cust_params["sort"], ["name", "registered_at", "postal_code"]) if customers.class != String

if customers.class == String #return the error
render json: {ok: false, message: customers }, status: :not_found
else
render json: customers.as_json( only: [:id, :name, :registered_at, :postal_code, :phone, :movies_checked_out_count] ), status: :ok
end
end

# GET /customers/:id/current
# List the movies a customer currently has checked out (using customer id as params)
def current
if @customer
current_rentals = @customer.find_rentals('checked out')
current_rentals = Customer.paginate_check(current_rentals, cust_params["p"], cust_params["n"])
current_rentals = Customer.sort_check(current_rentals, cust_params["sort"], ["title", "check_out_date", "due_date"]) if current_rentals.class != String

if current_rentals.class == String #return the error
render json: {ok: false, message: current_rentals }, status: :not_found
elsif current_rentals == []
render json: { ok: true, message: "#{@customer.name} has 0 movies checked out."}, status: :ok
else
current_rentals.map { |rental| { title: rental.movie.title, check_out_date: rental.check_out_date, due_date: rental.due_date } }
render json: { current_rentals: current_rentals }, status: :ok
end
end
end

# GET /customers/:id/history
# List the movies a customer has checked out in the past
def history
if @customer
past_rentals = @customer.find_rentals('returned')
past_rentals = Customer.paginate_check(past_rentals, cust_params["p"], cust_params["n"])
past_rentals = Customer.sort_check(past_rentals, cust_params["sort"], ["title", "check_out_date", "due_date"]) if past_rentals.class != String

if past_rentals.class == String #return the error
render json: {ok: false, message: past_rentals }, status: :not_found
elsif past_rentals == []
render json: { ok: true, message: "#{@customer.name} has 0 past rentals."}, status: :ok
else
render json: { past_rentals: past_rentals }, status: :ok
end
end
end

private
def find_customer
@customer = Customer.find_by(id: cust_params["id"])

if @customer.nil?
render json: { ok: false, message: "Unable to find customer with ID: #{cust_params["id"]}."}, status: :not_found
end
end

def cust_params
params.permit(:sort, :n, :p, :id)
end
end
Loading