Skip to content
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

Emilce and Maja Octos #23

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open

Emilce and Maja Octos #23

wants to merge 50 commits into from

Conversation

mgraonic
Copy link

Dear Reviewer: did we do error handling correctly (ie, is this fine for the next iteration of this assignment)? What could we have done better with error handling and inventory checking?

Comprehension Questions

Question Answer
Explain how you came up with the design of your ERD, based on the seed data. We observed the seed data and determined which models were necessary and their relationships to each other. We created an ERD and moved quickly to create the db based off that.
Describe a set of positive and negative test cases you implemented for a model. Testing models was not required for this assignment.
Describe a set of positive and negative test cases you implemented for a controller. Positive test cases included if a movie was able to be checked out/in. Negative test cases involved not allowing customers to checkout a movie that didn't exist (or no inventory).
How does your API respond when bad data is sent to it? We provide error handling with bad request/not found statuses. We also provide specific errors in consistent hash structures.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. Check available number of movies and a custom validation that ensures there is enough available inventory to make a rental
Do you have any recommendations on how we could improve this project for the next cohort? This was a good project. We liked that there was no model validation testing and we appreciated the ample project time!
Link to Trello https://trello.com/b/cM8JJ0TS/videostore-api
Link to ERD https://www.lucidchart.com/invitations/accept/991732d6-6586-4644-ba4f-be42e616dc45

mgraonic and others added 30 commits May 7, 2018 13:49
@droberts-sea
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene yes
Comprehension questions yes
General
Business Logic in Models mostly - see RentalsController
All required endpoints return expected JSON data yes
Requests respond with appropriate HTTP Status Code yes
Errors are reported yes, this error handling looks fine to me.
Testing
Passes all Smoke Tests yes
Model Tests - all relations, validations, and custom functions test positive & negative cases no - Model testing was most certainly a requirement on this project. To quote the Wave 1 requirements: "As with all Rails projects, model testing is a requirement. You should have at least one positive and one negative test case for each relation, validation, and custom function you add to your models."
Controller Tests - URI parameters and data in the request body have positive & negative cases yes - excellent work, especially on the RentalsController
Overall Good work overall. Aside from the missing model tests, my one complaint is that it was difficult to get your project up and running locally - your migrations didn't all run, and your seeds created invalid customers (movies_checked_out_count set to nil instead of 0). In general I'm quite happy with this submission, particularly your error handling and controller tests. Keep up the hard work!

validates :address, presence: true
validates :city, presence: true
validates :state, presence: true
validates :postal_code, presence: true

Choose a reason for hiding this comment

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

You're over-validating here. Your app will not break if the phone number or zip code is missing, and spending the time to validate, test the validations, and make sure your other tests respect them is more effort than you should be spending, especially for a school project where working with models is not the core learning goal.

# if rental is back, due_date is nil
def available_inventory
unavailable = 0
self.rentals.each do |rental|

Choose a reason for hiding this comment

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

I like that you calculate this on the fly rather than storing the value.


# calculates and returns a movie's available inventory
# if rental is out, then due_date is a Date object
# if rental is back, due_date is nil

Choose a reason for hiding this comment

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

I'm not sure that I agree with this design decision. Having information about the due dates of old rentals might be useful, especially in a real-world version of this app. For the context of this project it works fine, but destroying this information makes me nervous.

private
def available?
if self.movie.available_inventory <= 0
errors.add(:movie_id, "This movie is not in stock.")

Choose a reason for hiding this comment

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

Nice work with this custom validation!

# rental = Rental.where(movie_id: movie_id, customer_id: customer_id).where.not(due_date: nil).first

rental = Rental.where.not(due_date: nil).where(movie_id: movie_id, customer_id: customer_id).order(checkout_date: :desc).first
# rental = Rental.where(movie_id: movie_id, customer_id: customer_id).order(checkout_date: :desc).where.not(due_date: nil)

Choose a reason for hiding this comment

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

This is a really complex database query! Could you encapsulate it as a self method on Rental? Maybe something like Rental.outstanding(movie_id, customer_id)


# increase the customer's checked-out movie number
customer.movies_checked_out_count += 1
customer.save

Choose a reason for hiding this comment

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

You do a lot of work in this function: calculating dates, creating a Rental, increasing the movie count. It would be good to encapsulate all that in one model method.

end
else
render json: {errors: { id: ["Must enter a valid movie and customer"]}}, status: :bad_request
end

Choose a reason for hiding this comment

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

Here you should probably specify which field is bad. id by itself doesn't correspond to either of the parameters the client sent.

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