-
Notifications
You must be signed in to change notification settings - Fork 24
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
Amy & Christiane -- Carets #20
base: master
Are you sure you want to change the base?
Conversation
…e a test given valid data
…modate validations
…nges controller test accordingly
Serializer
…ntals serializer, created a pretty date method (not working as expected, need to go back to it later), implemented the check_out method in the rentals controller
…oute, laid out pseudocode for Customers#overdue
Video StoreWhat We're Looking For
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
movie = Movie.find_by_id(params[:movie_id]) | ||
customer = Customer.find_by_id(params[:customer_id]) | ||
|
||
unless movie.available_inventory > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if movie
is nil
??
I notice the seeds file has all the movies started off with nil
for available inventory, when I ran this locally.
@@ -0,0 +1,3 @@ | |||
class MovieSerializer < ActiveModel::Serializer | |||
attributes :title, :overview, :release_date, :inventory, :available_inventory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id field???
@@ -0,0 +1,59 @@ | |||
class CustomersController < ApplicationController | |||
def index | |||
customers = Customer.all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your customers don't have a count of the movies checked out!
def overdue | ||
# overdue_rentals = Rental.where("movie_id = ? AND customer_id = ?", movie.id, customer.id) | ||
# theoretical: has_overdue? | ||
customers_with_overdue= Customer.all.select {|customer| customer.has_overdue?} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this will work, it's usually better to let the database do a lot of the work, with some sort of where
clause, probably in a class method of Customer
which selects movies which are overdue.
The database is almost always faster about this.
@@ -0,0 +1,3 @@ | |||
class CustomerSerializer < ActiveModel::Serializer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Serializers, Neat!
@@ -0,0 +1,24 @@ | |||
class ApplicationController < ActionController::API | |||
|
|||
def build_overdue_array(rentals_array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here? This looks like it should be in the model!
Come to think of it it looks like it is!
|
||
overdue_customers_array = [] | ||
|
||
customers_with_overdue.each do |customer| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be in the model
render json: { ok: false, message: "No checked out copy of #{movie.title} for #{customer.name} found" }, status: :not_found | ||
end | ||
|
||
if checked_out.count > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again this kind of functionality should go in the model.
@@ -0,0 +1,3 @@ | |||
class CustomerSerializer < ActiveModel::Serializer | |||
attributes :registered_at, :name, :address, :city, :state, :postal_code, :phone, :movies_checked_out, :id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However no movies_checked_out_count
Video Store API
Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.
Comprehension Questions