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

Elle and Cyndi #23

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

Elle and Cyndi #23

wants to merge 20 commits into from

Conversation

dev-elle-up
Copy link

@dev-elle-up dev-elle-up 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. Upon looking at the seed data, we noticed we'd need two models - movie and customer - and used the column headings to determine what our columns would be called. Then we read through the project spec and noticed we'd need one more column in each of these tables and we also needed a table for Rentals.
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 to look up /customers and /movies is O(n) because the amount of time it takes to find all of the customers or movies depends on how many entries are in each table.
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 of this endpoint is O(log n). The time complexity depends on what the code uses to look up the customer and movie. In our case, it uses the id of the customer and movie to look up the rental, which means a binary search can be used. This results in O(log n) time complexity.
Describe a set of positive and negative test cases you implemented for a model. For the Movie model, we tested that a movie can be created given valid data and that a movie won't be created if the title is missing, since we require title.
Describe a set of positive and negative test cases you implemented for a controller. We wrote tests for a rental that both can and cannot be checked in. Specifically, we tested that a rental can be checked in if a matching valid rental exists, and made sure that we got the expected status response if there was no matching rental (no customer_id & movie_id that both match a rental).
How does your API respond when bad data is sent to it? We return a status of either :no_content or :bad_request and a corresponding message, as json.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. One of our custom model methods takes a customer id and a movie id and returns a rental. We put this in a method because it's not part of a controller action and felt more like business logic. We wanted to move more of this action to the model but it would break tests and we were approaching the deadline. We also put logic for checking in & out a movie in the rentals model. This made sense here because it updated the available_inventory and movies_checked_out_count for the associated movie and customer, which was business logic.
Do you have any recommendations on how we could improve this project for the next cohort? The description of the project was a little vague / unclear and hard to interpret. Putting more info in the intro regarding the final expected outcome would be helpful.
Link to Trello We did not create a Trello board. We did pair program the entire time and kept track of everything on paper.
Link to ERD https://drive.google.com/file/d/1fvZMhhrWEoHXR_MejhaDgQ3P6IVwlG9Y/view?usp=sharing
Summary Pairing with a person in another class was fun!

@CheezItMan
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Reasonable number of commits and good commit messages
Comprehension questions Check
General
Business Logic in Models Yes, but see my comments in rental.rb.
All required endpoints return expected JSON data Check
Requests respond with appropriate HTTP Status Code See my notes on some of your response codes.
Errors are reported Check
Testing
Passes all Smoke Tests Check
Model Tests - all relations, validations, and custom functions test positive & negative cases Very skimpy model testing.
Controller Tests - URI parameters and data in the request body have positive & negative cases Overall pretty good, see my inline notes
Overall Nice work, everything functions as required. For your design I think the available_inventory and checkout_count should be methods instead of data fields just because it could otherwise be possible to get them out of sync. You also have some status codes that could be better chosen. You also had some of the optionals done, nice work. You hit the major learning goals.

end

def self.return(customer_id, movie_id)
rental = Rental.find_by(customer_id: customer_id, movie_id: movie_id)

Choose a reason for hiding this comment

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

How do you know the customer only had one checked out?

belongs_to :movie, dependent: :delete
belongs_to :customer, dependent: :delete

def checkout_update_customer_movie(customer, movie)

Choose a reason for hiding this comment

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

The number checked out and available inventory sound like methods instead of data fields to me. I could see they getting out of sync especially if other apps impacted the same database.

if !customers.empty?
render json: customers.as_json(except: [:created_at, :updated_at]), status: :ok
else
render json: {message: "There are currently no customers."}

Choose a reason for hiding this comment

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

You should include a status code.

if !movies.empty?
render json: movies.as_json(except: [:created_at, :updated_at]), status: :ok
else
render json: {message: "There are currently no movies."}

Choose a reason for hiding this comment

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

Status code?

def checkout
movie = Movie.find_by(id: params[:movie_id])
if movie == nil
render json: { error: "Movie was not found in database or no movie id was provided." }, status: :no_content

Choose a reason for hiding this comment

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

Status: no_content is usually for when the app has no content to return to the user, not when the operation fails. Instead I suggest, :bad_request.


describe Customer do
let(:customer) { Customer.new }

Choose a reason for hiding this comment

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

No validations???


it "returns false for invalid movie data" do
movie = Movie.new
movie.valid?.must_equal false

Choose a reason for hiding this comment

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

No test for why it's not valid?

rental.customer.must_equal customers(:one)
end
end

Choose a reason for hiding this comment

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

For these methods, what about testing checkouts when the inventory isn't available?

What about checking in a movie that's never been checked out, or was already checked in?

get customers_path
body = JSON.parse(response.body)
body.each do |customer|
customer.keys.must_equal keys

Choose a reason for hiding this comment

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

If you don't care about the order, I'd suggest that you sort the keys before comparing them.

must_respond_with :success
end

it "will return bad request if given invalid data" do

Choose a reason for hiding this comment

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

You should also try this with invalid customer_id

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