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

Ann and Regan's Fine Fine Video Store API #3

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

Conversation

pancake-batfish
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 knew that customers had to have many movies, and movies could have many customers, so we knew we needed to join them through rentals.
List all the completed endpoints of your application. GET /movies, GET /customers, GET /movies/:title, POST /rentals/title/check-out, POST /rentals/title/check-in, GET /rentals/overdue
Describe a set of positive and negative test cases you implemented for a model. Rental, e.g.: can be created with an associated movie and customer; negative case is that it cannot be created without a movie id or without a customer id
Describe a set of positive and negative test cases you implemented for a controller. Rental controller checkin action: positive case: modifies the db when a checkin occurs; negative: does not change the db if the wrong data is provided
How does your API respond when bad data is sent to it? generally it returns the status :bad_request
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We have a custom model method to return the number of active rentals for a given customer (where the rental exists with that customer's id and the checkin_date is nil). We wrapped this functionality in a method so we could easily render this number as part of our json response.
Do you have any recommendations on how we could improve this project for the next cohort? We think this was well-designed.
Link to Trello [https://trello.com/b/GmLbDpiz/videostore-api ]
Link to ERD (image embedded in our Trello board)

@CheezItMan
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene
Comprehension questions I can't get access to your Trello, can you reshare it with me and I'll revisit the project?
General
Business Logic in Models Good work creating custom methods to calculate values and provide data to the JSON.
All 3 required endpoints return expected JSON data Check
Requests respond with appropriate HTTP Status Code Check
Errors are reported Check, well done using errors hash. Also good work using JSON to report the errors along with status codes.
Testing
Passes all Smoke Tests Check, well done
Model Tests - all relations, validations, and custom functions test positive & negative cases You have a test, it "must be able to create valid customer and return corresponding data" do, that I'm not sure what it's actually testing. You do have lots of positive and negative tests. Good use of Chronic in the rental_test.
Controller Tests - URI parameters and data in the request body have positive & negative cases Check, positive and negative tests & also tests for the correct order things are delivered.
Optionals
POST routes use URI parameter and request body to add a new record to the database Nice work!
GET /customers shows how many movies are checked out by a customer Check, nicely done
GET /movies/:title shows updated inventory Check
Overall Nicely done, you've done a great job with testing & had all the options. Excellent work!

@pancake-batfish
Copy link
Author

pancake-batfish commented May 19, 2017 via email

Copy link

@eabrash eabrash left a comment

Choose a reason for hiding this comment

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

Nice job on this! I think you did a really great job of designing your solution for the assignment and structuring it in a logical, intuitive way. Your code was really easy to follow and made sense to me right away. I've left a few comments on specific sections where I had questions or where you might be able to refactor for greater clarity or to make sure edge cases are covered. If you have any questions, feel free to let me know. Again, I think you did a really good job! :)

render status: :bad_request, json: { error: "no customer found"}
else
# find the rental in question based on params[:title] and params[:customer_id]
rental = Rental.find_by(customer_id: customer.id, 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.

I think this might not be a watertight way of identifying rentals. For instance, supposed a customer has three simultaneously checked-out copies of Jaws. I believe that find_by will only give you the one of these that happens to be first in the list. Since you don't currently limit retrieval by whether the rental is checked in, I think the same (already checked in) Jaws rental instance would be retrieved each time, making it impossible to check the other Jaws rental instances in. At least, this seems to be what I observe when I test via Postman. Not a big deal, but maybe something to look into if you plan to use this API in a future project.

rental.save
# movie.inventory += 1
# movie.save
render status: :ok, json: { nothing: true }
Copy link

Choose a reason for hiding this comment

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

This might just be my own lack of familiarity with API development, but I found the {"nothing": true} JSON response a little confusing, especially since it could appear in the context of both error statuses and 200 OK statuses. It might be helpful for users of the API if you could customize the "nothing": true responses to provide a little more specific information, i.e., {"result": "Rental of Movie X by Customer Y was successfully checked in"}. Though this may be a convention/requirement of the assignment that I'm just not aware of :)

if @rental.save
# movie.inventory -= 1
# movie.save
render status: :ok, json: @rental.as_json
Copy link

Choose a reason for hiding this comment

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

You might want to filter what's returned here to eliminate the created_at and updated_at timestamps from the database record. They seem to be in a different timezone than the local user's timezone (i.e., for me they said it was already tomorrow, "2017-06-05T03:08:04.102Z", while the checkout date was today as expected, "2017-06-04T00:00:00.000Z"). It's not a big deal but could be somewhat confusing from the API user's standpoint.

#should subtract from the inventory the number of copies out in active rentals (checkin_date = nil)
rentals = Rental.where(movie_id: self.id, checkin_date: nil)
return self.inventory - rentals.size
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 is an elegant way of making sure the available inventory always tracks with the rental database in its most updated form.

# if you're sharing your code publicly.

development:
secret_key_base: df155bf0d4a6b976d3353d144d683fe2cc4a813adb6be6677373df15a64e12f4c269ef434ae3c1c3ecaf5232beb500d448ba39b72a9bab543ff1408ef864eec3
Copy link

Choose a reason for hiding this comment

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

Should this file be git ignored to avoid sharing these keys publicly? Or is that only an issue for the prod key (which I see is already hidden)?

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.

5 participants