Skip to content
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

Queues - Danielle Birbal & Marisol Lopez - VideoStoreAPI #4

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7e75b26
initial rails app setup
marisol-lopez May 9, 2017
4763720
Generated Customer Model
birbalds May 9, 2017
ae9a672
movies migration, join-table migration, added account_credit
marisol-lopez May 9, 2017
399937f
added routes
marisol-lopez May 9, 2017
b23daf0
created customers controller
marisol-lopez May 9, 2017
91a286a
added controller tests
marisol-lopez May 9, 2017
dc75806
added test for customer relation
marisol-lopez May 9, 2017
1d45957
Added Movies Controller + Controller Tests
birbalds May 9, 2017
b1ddd6d
Merge branch 'moviefunkdev'
birbalds May 9, 2017
766fb6a
Merge remote-tracking branch 'origin/master'
birbalds May 9, 2017
5b5733d
created rentals model
marisol-lopez May 9, 2017
13589da
migration for rentals
marisol-lopez May 10, 2017
eeedbcd
Expirementing with rental functionality
birbalds May 10, 2017
74d35c7
Merge branch 'moviefunkdev'
birbalds May 10, 2017
25d60ba
changed rentals yml and customer relationship and test
marisol-lopez May 10, 2017
4eddd7c
updated tests for movie and customer relationships
marisol-lopez May 10, 2017
5e4f2d4
Added CheckIn and CheckOut
birbalds May 10, 2017
deac560
Merge branch 'moviefunkdev'
birbalds May 10, 2017
fa7dbcc
serializer
marisol-lopez May 10, 2017
2f7d2d0
merge conflict routes
marisol-lopez May 10, 2017
f873171
rentals overdue method
marisol-lopez May 10, 2017
6559b82
Fixed customer movie count
birbalds May 10, 2017
327973b
Merge branch 'master' of https://github.com/marisol-lopez/VideoStoreAPI
marisol-lopez May 10, 2017
7fd5aca
created methods for overdue rentals method to print out movie title, …
marisol-lopez May 10, 2017
b8d4502
Removed unnecessary line
birbalds May 10, 2017
8e713dd
tests for rental model and controller
marisol-lopez May 11, 2017
d6c3a6b
added test for rentals if there are no overdue rentals
marisol-lopez May 12, 2017
e2744f2
changed default value for checkout count fixed negative test case for…
marisol-lopez May 12, 2017
a706934
Added test + validations
birbalds May 12, 2017
ee04348
Tests for validations
birbalds May 12, 2017
acdc4ac
added error reports to movies and customers controller
marisol-lopez May 12, 2017
7aa5b7c
Merge branch 'master' of https://github.com/marisol-lopez/VideoStoreAPI
marisol-lopez May 12, 2017
72230a9
changed checkout and checkin routes
marisol-lopez May 12, 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
Prev Previous commit
Next Next commit
serializer
marisol-lopez committed May 10, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fa7dbcc907b12ddca3ecaaaf9b8fc14b78b69f48
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -25,6 +25,8 @@ gem 'puma', '~> 3.0'
# 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
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -24,6 +24,11 @@ GEM
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)
@@ -52,6 +57,8 @@ GEM
debug_inspector (>= 0.0.1)
builder (3.2.3)
byebug (9.0.6)
case_transform (0.2)
activesupport
coderay (1.1.1)
concurrent-ruby (1.0.5)
debug_inspector (0.0.3)
@@ -65,6 +72,7 @@ GEM
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)
@@ -158,6 +166,7 @@ PLATFORMS
ruby

DEPENDENCIES
active_model_serializers (~> 0.10.0)
better_errors
binding_of_caller
byebug
13 changes: 9 additions & 4 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class CustomersController < ApplicationController
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
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
def overdue
@rentals = Rental.where('due_date <= ?', Time.now)
render :json => @rentals, status: :ok
end

end
5 changes: 2 additions & 3 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Customer < ApplicationRecord
has_many :movies, through: :rentals
has_many :rentals

has_many :movies, through: :rentals
has_many :rentals
end
2 changes: 2 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Movie < ApplicationRecord
has_many :customers, through: :rentals
has_many :rentals
#
# def return_movie_title
end
2 changes: 2 additions & 0 deletions app/models/rental.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Rental < ApplicationRecord
belongs_to :movie, foreign_key: 'movie_id'
belongs_to :customer, foreign_key: 'customer_id'


end
17 changes: 17 additions & 0 deletions app/serializers/rental_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class RentalSerializer < ActiveModel::Serializer
attributes :other_items, :customer_id, :checkout_date, :due_date

def other_items
rentals = Rental.where('due_date <= ?', Time.now)
overdue_hash = {}
array = []
rentals.each do |rental|
overdue_hash[:title] = rental.movie.title
overdue_hash[:name] = rental.customer.name
overdue_hash[:postal_code] = rental.customer.postal_code
array << overdue_hash
end
return array
end

end
12 changes: 7 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

get '/customers', to: 'customers#index', as: 'customers'
get '/movies', to: 'movies#index', as: 'movies'
get '/movies/:title', to: 'movies#show', as: 'movie'
get '/customers', to: 'customers#index', as: 'customers'
get '/movies', to: 'movies#index', as: 'movies'
get '/movies/:title', to: 'movies#show', as: 'movie'

post '/movies/:title/check-out', to: 'movies#checkout', as: 'checkout'
post '/movies/:title/check-out', to: 'movies#checkout', as: 'checkout'

get '/rentals/overdue', to: 'customers#overdue', as: 'overdue'
end