-
Notifications
You must be signed in to change notification settings - Fork 25
Karis & Dionisia VideoStoreAPI - Edges #20
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?
Conversation
created controllers and models
testing for customer model
created tests for movies model
added routes
customers controller and tests complete
movies controllers and tests passing
…ustomers and added tests for those validations
Karis setup
Karis setup
Karis setup
fixed avail inventory issue
merge conflict fixed
Dionisia work
rentals tests
rentals controller tests added
added tests for model methods
Video StoreWhat We're Looking For
|
| # binding.pry | ||
| if rental.save | ||
| rental.movie.increment_inventory! | ||
| rental.customer.decrement_movies_checked_out_count! |
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.
There's a lot of work being done in this function. Could you wrap this all up in a model method (maybe Rental.checkin(customer_id, 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.
Also, what happens if the rental saves, but incrementing the inventory or decrementing the checkout count fails somehow? You would be in a sticky situation.
We didn't talk about this in class, but the solution here is to use a transaction. If you're interested in learning about this, see https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html
| # binding.pry | ||
| movie.decrement_inventory! | ||
| customer.increment_movies_checked_out_count! | ||
| # binding.pry |
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.
As above, it would be great to wrap all this up in a model method.
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
First, what is
n? The number of movies or customers? You should specify this explicitly.Second, what about finding the rental count? In your code you track this count in the database, so it doesn't add any extra time to the
indexoperation. Are there other ways to do it that would?POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.nis the number of Rentals, this is not quite correct. Calling.ordersorts the entire list, which means the time complexity isO(n log(n)). However, since you only need the first matching rental, you don't need to call order, you could use.max_byinstead and get linear complexity.