-
Notifications
You must be signed in to change notification settings - Fork 26
Kim & Niv #14
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
base: master
Are you sure you want to change the base?
Kim & Niv #14
Conversation
…elations tests accordingly
Kf/model relations tests
…increase_inventory and set_check_in
removing inventory adjustments from check-in action
Kf/simplecov
Kf/movie validation tests
Video StoreWhat We're Looking For
|
| def index | ||
| customers = Customer.all | ||
| render json: customers.as_json(only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone], methods: :movies_checked_out_count), status: :ok | ||
| end |
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.
I would probably break like 5 across multiple lines for readability.
| if movie.save | ||
| render json: { id: movie.id }, status: :ok | ||
| else | ||
| render json: { errors: movie.errors.messages }, status: :bad_request |
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.
The error response on line 22 doesn't match the one in show above (line 12). That one has ok and messages as the keys, but this one sends errors. Best practice is to pick one error reporting format and stick with it.
| customer = Customer.find_by(id: params[:customer_id]) | ||
| error = "Customer not found" if customer == nil | ||
|
|
||
| movie = Movie.find_by(id: params[:movie_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.
You have a bunch of business logic here! Would it be possible to encapsulate this in a model method? Something like
Rental.check_out(customer_id, movie_id)
might be a good interface. That would make this logic easier to test as well.
|
|
||
| def movies_checked_out_count | ||
| return Rental.where(check_in_date: nil).count | ||
| end |
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.
I love that you made Customer#movies_checked_out_count and Movie#available_inventory methods instead of storing them in the database. That way there's no way to forget to update these values.
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
POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.