Open
Conversation
Wave1 testing
Wave1 testing
Optional Enhancement - Sorting
Video StoreWhat We're Looking For
|
CheezItMan
reviewed
Nov 23, 2019
| KEYS = [:id, :name, :address, :city, :state, :postal_code, :phone, :registered_at, :movies_checked_out_count] | ||
|
|
||
| def index | ||
| if ["name","registered_at", "postal_code"].include? params[:sort] |
| belongs_to :movie | ||
| belongs_to :customer | ||
|
|
||
| def decrease_available |
There was a problem hiding this comment.
I like that you moved some business logic here.
However it's not a good idea to keep the available movies in a field, but rather calculate from the total inventory and the number of outstanding rentals. Otherwise it's possible for things to get out of sync if other applications use the same database.
| @@ -0,0 +1,41 @@ | |||
| require "test_helper" | |||
|
|
|||
| describe Rental do | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.POST /rentals/check-inis O(n) because the first thing the check-in action does is locate the rental. The worst case scenario is that the rental would be the last record in the database meaning that thefindfunction would traverse all records in the database, which is O(n) with n being the number of rentals in the database. All other steps in this action are assigning values to the already found object, which does not worsen the time complexity.ok: falsein the JSON along with an appropriate HTTP status (:bad_request, :not_found).movies_checked_out_countsince both adjustments need to occur when the action is called. We chose to put this in a model method because it is making adjustments to the database, which we determined counts as "business logic". It is also a self-contained bit of code that peeled out of the controller keeps the controller nice and tidy.