Skip to content

Conversation

@minams
Copy link

@minams minams commented May 17, 2019

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 looked at the fields that were listed for the seed data and determined that they would be our models. We then structured our join table as Rentals.
What would be the Big-O time complexity of your /customers & /movies endpoints? What does the time complexity depend on? Explain your reasoning. customers#index = O(n) where n = the number of customers. movies#index = O(n) where n = the number of movies. movie#show = O(n) where n = the number of movies it take to find that particular movie id. movie#create O(1) since the creation is just inserting to the end.
What is the Big-O time complexity of the POST /rentals/check-in endpoint? What does the time complexity depend on? Explain your reasoning. O(n)where n is the number of movies it takes to find the movie id.
Describe a set of positive and negative test cases you implemented for a model. Positive cases: we tested for when all of the elements were present, i.e., a valid movie consisted of a title, overview, release date, and inventory. The negative cases were if any of them were absent.
Describe a set of positive and negative test cases you implemented for a controller. Positive cases we tested for that we ended up with the successful pathway or action. Negative cases are the errors that returned if we had invalid information.
How does your API respond when bad data is sent to it? It renders an error.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. A customer model method we decided to create was to check if the movie is available for rental. We decided to create this so that it wasn't so embedded in the rental process.
Do you have any recommendations on how we could improve this project for the next cohort? No recommendations! Thought this was a nice post bEtsy project and intro to the other side of API.
Link to Trello https://trello.com/b/M054vfVN/videostoreapi
Link to ERD ERD in Trello: https://trello.com/b/M054vfVN/videostoreapi
Summary

gracemshea and others added 30 commits May 14, 2019 13:28
relationship tests for customer and rental
added positive test for movie model
@tildeee
Copy link

tildeee commented May 23, 2019

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene x
Comprehension questions x
General
Business Logic in Models Some, but could overall be improved. Comments below
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, all required tests pass
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

Well done on this project, you two!

I'm really happy with how the controller tests and the model tests look. It has some really nice readable code style there.

I think that the project could have been better with a better understanding of models. There were a lot of places that could be improved with better execution on:

  • instances of models that have relationships with other models can access those with things like movie.rentals, rental.movie, etc.
  • instance methods on models should be relevant to that model itself
  • even small pieces of functionality can be pulled from the controller to the model

I also saw some places of weird, messy code... and places that could be refactored to use nicer forms of code. It's getting to that point of the curriculum -- I fully believe y'all can do better code style!

That being said, you two did very well on this project overall. Good work!


if rental.movie_avail?(rental_params[:movie_id])
if rental.save
customer = Customer.find_by(id: rental.customer_id)
Copy link

Choose a reason for hiding this comment

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

Hm, did you know that customer = Customer.find_by(id: rental.customer_id) is the same thing as customer = rental.customer, since Rental belongs to Customer?

if rental.movie_avail?(rental_params[:movie_id])
if rental.save
customer = Customer.find_by(id: rental.customer_id)
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.

This business logic would be better if moved to the model. Maybe a new instance method, like customer.increase_checkout?

rental = Rental.new(rental_params)
rental.check_out = Date.today
rental.check_in = rental.check_out + 7
rental.status = "unavailable"
Copy link

Choose a reason for hiding this comment

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

All of this work on the new rental may be better as a model method

customer.movies_checked_out_count += 1
customer.save

movie = Movie.find_by(id: rental.movie_id)
Copy link

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 better to utilize the fact that rental belongs to movie, and do movie = rental.movie

customer.save

movie = Movie.find_by(id: rental.movie_id)
movie.available_inventory -= 1
Copy link

Choose a reason for hiding this comment

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

This business logic would be better if moved to the model. Maybe a new instance method, like movie.decrease_inventory?

has_many :rentals

def movies_checked_out_count
total = 0
Copy link

Choose a reason for hiding this comment

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

Why is there a variable named total?

def movies_checked_out_count
total = 0
num_unavailable = 0
num_unavailable = 0
Copy link

Choose a reason for hiding this comment

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

Why is this line duplicated?

if rental.status == "unavailable"
num_unavailable += 1
end
end
Copy link

Choose a reason for hiding this comment

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

Nice each loop! Instead of an each loop, could we do something like Enumerables filter or count method?

num_unavailable += 1
end
end
return (movies_count = num_unavailable)
Copy link

Choose a reason for hiding this comment

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

Hm, what does return (movies_count = num_unavailable) mean? Although it's a valid line of code, it's hard to read. What are you returning? Why would you need to do assignment to another variable?

validates :movie, :customer, :check_out, :check_in, :status, presence: true

def movie_avail?(movie_id)
movie = Movie.find_by(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.

This method has nothing to do with Rental! So I'm not convinced it needs to be an instance method on Rental. Should move this method to the Movie file?

validates :movie, :customer, :check_out, :check_in, :status, presence: true

def movie_avail?(movie_id)
movie = Movie.find_by(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.

Also, do we need to pass in a movie_id? If it's on the Movie, then it should reference itself. Otherwise, if it's on the Rental, then we should reference the movie through rental, since rental belongs to movie

return true
else
return false
end
Copy link

Choose a reason for hiding this comment

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

Could we simplify this code somehow? Consider:

if !movie.nil? && movie.inventory > 0
  return true
end

return false

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