Skip to content

Conversation

@sarabrandao21
Copy link

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

Prompt Response
Explain how you came up with the initial design of your ERD, based on the seed data and reading through the API endpoints We came to our initial draft knowing we needed a customer and video model 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 a videos_checked_out_count column on our customer model, so we added that to make the migration successful and seed our database. Final ERD
What would be the Big-O time complexity of your /customers & /videos endpoints? What does the time complexity depend on? Explain your reasoning. The Big-O time complexity of these endpoints is O(n * log n), where n is the total number of customers or videos. In the index action in both controllers, we are querying the database for all customers or videos (O(n) operation), and then specifying a certain ordering (either by title or name), resulting in O(n* log n) overall.
What is the Big-O time complexity of the POST /rentals/check-in endpoint? What does the time complexity depend on? Explain your reasoning. The Big-O time complexity of the checkin endpoint 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.
Describe a specific set of positive and negative test cases you implemented for a model. We implemented a set of model tests that check that a valid rental can be created with the correct fields (customer_id, video_id, and due_date), and conversely, NOT be created without those fields being present and referencing an existing customer and video in the database. In the first case, we expected that the rental would be valid (true), but would fail to be valid for the second case (false).
Describe a specific set of positive and negative test cases you implemented for a controller. We implemented positive test cases for the video controller index action when we tested whether it returns proper json for fields for a list of existing videos. For the negative test case, we tested that the index action returns an empty array if no videos exist in the system.
Broadly, describe how an API should respond when it handles a request with invalid/erroneous parameters. An API should return back JSON with error messages that alert the viewer what may have gone wrong (with the status code) with the parameters or invalid request.
Describe one of your custom model methods and why you chose to wrap that functionality into a method.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We chose to make an increment_videos_checked_out_count instance method on the Rental model, which would be run after initializing a new Rental instance (along with decrement_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

Ada and others added 30 commits May 26, 2020 14:03
…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.
Copy link

@kaidamasaki kaidamasaki left a 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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fancy!

@kaidamasaki
Copy link

Video Store API

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Practices git with at least 10 small commits and meaningful commit messages ✔️
Understands the importance of how APIs handle invalid/erroneous data in their reflection questions ✔️
Practices Rails best practices and well-designed separation, and encapsulates business logic around check-out and check-in in models ✔️
Uses controller tests to ensure quality code for every route, and checks for response status and content, with positive cases and negative cases ✔️
Uses controller tests to ensure correctness for check out and check in requirement, and that checked out counts and inventories appropriately change ✔️

Functional Requirements

Functional Requirement yes/no
All provided smoke tests for Wave 1 pass ✔️
All provided smoke tests for Wave 2 pass ✔️

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 3+ in Code Review && 2 in Functional Requirements ✔️
Yellow (Approaches Standards) 2+ in Code Review && 1+ in Functional Requirements, or the instructor judges that this project needs special attention
Red (Not at Standard) 0-1 in Code Review or 0 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging, or the instructor judges that this project needs special attention

Comprehension Question

This is just giving you a peek under the hood:

The Big-O time complexity of these endpoints is O(n * log n), where n is the total number of customers or videos. In the index action in both controllers, we are querying the database for all customers or videos (O(n) operation), and then specifying a certain ordering (either by title or name), resulting in O(n* log n) overall.

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).

The Big-O time complexity of the checkin endpoint 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.

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 Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever
Descriptive/Readable
Concise
Logical/Organized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants