Skip to content

Conversation

@sdbenezra
Copy link

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

Question Answer
Explain how you came up with the design of your ERD, based on the seed data. We reviewed the movie and customer data and realized we needed a third table to relate the two. That led us to create the rentals table to associate movies and customers. Then we added columns as necessary to complete the requirements under wave 2 and 3.
What would be the Big-O time complexity of your /customers & /movies endpoints? What does the time complexity depend on? Explain your reasoning. The time complexity for the index action of both movies and customers is O(n) (with n being the total number of movies or customers), because you must go through and output each movie and customer in the database.
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 time complexity is O(n) because the check in method calls the calculate_available_inventory method which needs to iterate through all of the rentals in the rentals table to check for which ones are currently rented. So in this case n would be equal to the total number of rentals in the table.
Describe a set of positive and negative test cases you implemented for a model. In the movie model there is a test that verifies approval of a non-negative inventory value, and a test that verifies a non-negative inventory value will not be saved.
Describe a set of positive and negative test cases you implemented for a controller. We have a test that will verify a rental is saved when given valid data, and a test that will verify a movie is not saved when either the movie or customer data is missing and render an error.
How does your API respond when bad data is sent to it? Our API sends an error message explaining what the error is and a status code of either :bad_request or :not_found.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We have several methods for calculating available inventory. We chose to create methods for these functions because we needed to use them in a few places and they felt more like involved business logic that belonged in a class instead of the controller.
Do you have any recommendations on how we could improve this project for the next cohort? The explanation about how postman works could be clearer. The video was slightly different than the actual interface, and the difference between entering params through the body vs the url was not explained well.
Link to Trello https://trello.com/b/76MxGw6O/api-videostore-michellesigrid
Link to ERD https://trello-attachments.s3.amazonaws.com/5be09689f40d3a3953cc7677/5be0971d8f7468185e20ed24/bfc341aabddb6a35cf158ea53e497b91/Screen_Shot_2018-11-05_at_12.18.58_PM.png
Summary

kangazoom and others added 30 commits November 5, 2018 11:31
prelim model (validations+relations) + controller tests for movie
…for returned customer data. Complete customer controller testing.
Add new movies_checked_out column for customers. Add json formatting …
set up movies routes + controller for index and show; create still un…
kangazoom and others added 20 commits November 7, 2018 11:52
Rework rentals checkin method to use post. Tests passing for all but inventor…
…tory methods. Fix reference to customer in customer test file.
Rework rentals controller and test to account for changed movie inven…
added null:false to movies inventory column
@tildeee
Copy link

tildeee commented Nov 20, 2018

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene x
Comprehension questions x
General
Business Logic in Models Could probably move some logic out from the RentalsController
All required endpoints return expected JSON data x
Requests respond with appropriate HTTP Status Code x
Errors are reported x
Testing
Passes all Smoke Tests x
Model Tests - all relations, validations, and custom functions test positive & negative cases x
Controller Tests - URI parameters and data in the request body have positive & negative cases x
Overall

Great work overall you two!

In general, great work on creating this API. The code could be tidied up in some parts, but it's overall good. I like your model and controller tests a lot, too.

I'm adding a few comments, but overall: well done

PS: This project lists Ruby 2.4.1 as a dependency even though we've been working in 2.5.1. Just curious?


def jsonify(customer_data)
return customer_data.as_json( only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone, :movies_checked_out_count])
end
Copy link

Choose a reason for hiding this comment

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

Nice


if movie
avail = movie.calculate_available_inventory
result = movie.save_available_inventory(avail)
Copy link

Choose a reason for hiding this comment

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

You end up assigning the result of movie.save_available_inventory(avail) into the variable result, but you don't use result anywhere... you probably don't need to assign this variable to anything


result = movie.save
if result
movie_id = movie.id
Copy link

Choose a reason for hiding this comment

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

Same as above: No need to make the movie_id variable here

if rental.save
inventory = movie.calculate_available_inventory()
movie.save_available_inventory(inventory)
customer[:movies_checked_out_count] += 1
Copy link

Choose a reason for hiding this comment

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

Could you make a method that increments the customer's checked out count field instead of operating on it directly here?

validates :movie_id, presence: true

def checked_out?()
return self.checkedout == true
Copy link

Choose a reason for hiding this comment

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

because of the nature of this conditional, you could probably just return self.checkedout

rental = Rental.new(rental_params)
if rental.save
inventory = movie.calculate_available_inventory()
movie.save_available_inventory(inventory)
Copy link

Choose a reason for hiding this comment

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

The two above lines are tightly coupled/repeated a lot. Could there be a method on Movie so an instance of Movie can update its available inventory itself?

body = JSON.parse(response.body)
expect(body).must_be_kind_of expected_type
return body
end
Copy link

Choose a reason for hiding this comment

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

Nice! This looks really slick! I really like this default argument!

body = JSON.parse(response.body)
expect(body).must_be_kind_of expected_type
return body
end
Copy link

Choose a reason for hiding this comment

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

Since this helper method is in multiple files, you could probably bring it out into the test_helper file

expect(body).must_include "errors"

must_respond_with :success
end
Copy link

Choose a reason for hiding this comment

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

Watch your indentation!

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