-
Notifications
You must be signed in to change notification settings - Fork 27
Space Sara and Becca #16
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
…or postman tests.
…to pass all wave 1 postman tests. Added edge case tests for missing video params; all passing.
…a customer and video before checkout and checkin methods.
kaidamasaki
left a comment
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.
Excellent job! Your code is clean and clear and I don't have too much to say about it. 😃
| if video.available_inventory <= 0 | ||
| render json: { errors: video.errors.messages }, status: :bad_request | ||
| return | ||
| elsif video && 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.
You already checked if video and customer were nil above.
| belongs_to :video | ||
|
|
||
| # Model methods with help from Sharon Cheung | ||
| after_create :increment_videos_checked_out_count, :decrement_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.
Fancy!
Video Store APIMajor Learning Goals/Code Review
Functional Requirements
Overall Feedback
Comprehension QuestionThis is just giving you a peek under the hood:
If you have an index on the column you are sorting by it brings the time complexity down to O(n) here. This is because database indexes provide efficient in-order traversal using auxiliary data structures (indexes are generally B-Trees).
Assuming you have indexes on all of these columns this lookup will be O(log(n)) where n is the largest of v, c or r because of the database doing a tree lookup. Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
Assignment Submission: Video Store API
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
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.
Reflection
customerandvideomodel to keep track of distinct data on the users of the product and the product itself. We thought we'd also need a rental model to keep track of how customers interacted with videos over time, and use the customer_id and video_id as foreign keys to connect the other two models. From the seed.rb script, we saw that we needed to have avideos_checked_out_countcolumn on our customer model, so we added that to make the migration successful and seed our database. Final ERD/customers&/videosendpoints? What does the time complexity depend on? Explain your reasoning.POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.checkinendpoint is dependent on the number of videos, customers, and rentals: O(v) + O(c) + O(r). Because we don't know which is largest/ most expensive to search for in the database, it's important to note the complexity of each kind of variable we're dealing with, because the total query will depend on finding all of them for a given rental: first to find the customer and video, and then to find if a rental belongs to both the customer and video.increment_videos_checked_out_countinstance method on the Rental model, which would be run after initializing a new Rental instance (along withdecrement_available_inventory). This method increments the customer's videos_checked_out_count by one every time a rental is issued for that customer, saves the data to the database, and returns the new count of videos checked out to that customer. This functionality allows us to automatically update the customer model every time a rental model instance is created - both convenient and clean for the related models to interact with each other in this way