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

AC's Video Rental API #21

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

AC's Video Rental API #21

wants to merge 29 commits into from

Conversation

acgillette
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. Initially there were no relationships established so they were just two tables, one for customers and one for movies. Later I added the rental model, which belonged to a movie and a customer.
List all the completed endpoints of your application. get /customers get /movies get /movies/:title post rentals/:title/check-out
Describe a set of positive and negative test cases you implemented for a model. In the movie controller, I tested that the inventory had to be a positive number by using a valid fixture and in invalid fixture
Describe a set of positive and negative test cases you implemented for a controller. For the rentals controller, I tested the create by making sure it returned success if the data was good, and bad_request if the data was not good
How does your API respond when bad data is sent to it? With a json containing the error messages
Describe one of your custom model methods and why you chose to wrap that functionality into a method. I chose to make available_inventory a class method instead of a column because I was having a lot of trouble figuring out how to automatically set it to inventory otherwise.
Do you have any recommendations on how we could improve this project for the next cohort?
Link to Trello I forgot to make a trello ):
Link to ERD https://www.lucidchart.com/invitations/accept/2c551072-b6c8-4df8-9a69-0d199aab8812

@kariabancroft
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Good
Comprehension questions Yes
General
Business Logic in Models Not really - though you are managing the available inventory here
All 3 required endpoints return expected JSON data Yes - hmmm it seems like you might have some code that has never run... looks like a typo on line #13 in rentals controller
Requests respond with appropriate HTTP Status Code Yes
Errors are reported Yes
Testing
Passes all Smoke Tests Yes
Model Tests - all relations, validations, and custom functions test positive & negative cases Some - though I think you skimped out on these a bit
Controller Tests - URI parameters and data in the request body have positive & negative cases Yes - looks good. Covers most scenarios in movie and the code you have for rentals
Optionals
POST routes use URI parameter and request body to add a new record to the database Yes
GET /customers shows how many movies are checked out by a customer Yes
GET /movies/:title shows updated inventory Yes
Overall Nice job hitting the major learning goals on this assignment

Copy link

@Erin007 Erin007 left a comment

Choose a reason for hiding this comment

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

Wahoo! Nice work - especially flying solo. Just a few things to think about. Please let me know if you have any follow up questions or would like me to take a closer look at something. -Erin

render status: :bad_request, json: { error: "Not enough inventory" }
elsif rental.save
render status: :ok, json: { id: rental.id }
rental.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.

If the rental is processed, the customer.movies_checked_out_count increments up one, which makes sense. Does the movie.available_inventory also need to decrease by one?

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

Choose a reason for hiding this comment

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

You could consider validating whether the data you're getting for these fields is consistent with what's expected. For example, is the postal code 6 digits? Big picture, you want to always validate that what is required exists, and if it exists, that the format (data type, length, etc) is what you want it to be.

validates :title, presence: true, uniqueness: true
validates :overview, presence: true
validates :release_date, presence: true
validates :inventory, presence: true, numericality: { greater_than: -1, only_integer: true }
Copy link

Choose a reason for hiding this comment

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

yeah! like, here where you check that the inventory is an integer or that movie names are unique. That's what I was thinking in my previous comment 🙂

Rails.application.routes.draw do

get '/movies', to: 'movies#index', as: 'movies'
get '/movies/:title', to: 'movies#show', as: 'movie'
Copy link

Choose a reason for hiding this comment

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

It's totally great as is, just know that you will more often than not (in my -admittedly limited - experience) see :id in the routes for show. There's a little Rails magic you can tap into if you use the convention of /model/:id in routes. If you're curious to Google or you come across something like resources :movies in a routes file, it's generating all of the routes for you and will format the show method with the id in the route.

@@ -0,0 +1,22 @@
# Be sure to restart your server when you modify this file.
Copy link

Choose a reason for hiding this comment

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

Shhhhh. These are secrets. They shouldn't float around out in the open. Pop this file in your gitignore.

@@ -0,0 +1,4 @@
class AddRelationships < ActiveRecord::Migration[5.0]
def change
Copy link

Choose a reason for hiding this comment

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

What's going on with this empty change method in this migration? Seems like you could delete this migration if it's not doing anything...


create_table "movies", force: :cascade do |t|
t.string "title"
t.string "overview"
Copy link

Choose a reason for hiding this comment

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

How long is the overview? I ask because I wonder if you want t.text rather than t.string.

Copy link

Choose a reason for hiding this comment

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

Nevermind, I re-read the instructions, but something to consider in the future.

r = JSON.parse(response.body)
r.length.must_equal Customer.count
end
end
Copy link

Choose a reason for hiding this comment

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

You could also spot check that the json data you're getting back is consistent with what you would expect for customers. Do the objects returned, for example, have telephone numbers etc?

customers(:no_code).valid?.must_equal false
customers(:no_phone).valid?.must_equal false
customers(:no_credit).valid?.must_equal false
end
Copy link

Choose a reason for hiding this comment

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

can a customer have negative credit?

Copy link

Choose a reason for hiding this comment

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

You'll want to test any of your relationships in these model tests, too. Like has_many etc


it "must be valid" do
value(rental).must_be :valid?
end
Copy link

Choose a reason for hiding this comment

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

what happens if you test an invalid rental?

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