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
|
| 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.
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 | |||
| @@ -0,0 +1,59 @@ | |||
| class CustomersController < ApplicationController | |||
| def index | |||
| customers = Customer.all | |||
There was a problem hiding this comment.
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.
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 | |||
| @@ -0,0 +1,24 @@ | |||
| class ApplicationController < ActionController::API | |||
|
|
|||
| def build_overdue_array(rentals_array) | |||
There was a problem hiding this comment.
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| |
| 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.
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.
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