Skip to content

Conversation

@shubha-rajan
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 thought about which attributes to include in each model and from that decided that the rental model would hold foreign keys for both customer and movie.
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 it takes to return every row in the table is dependent on the size of the table, so the time complexity is O(n).
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 POST /rentals/check-in endpoint time complexity is O(n) because the find_by method iterates through each value in the table until it finds one where all three of the column values that were given as arguments to find_by match.
Describe a set of positive and negative test cases you implemented for a model. To check the validity of our rental model, we tested to see whether the model was valid if all keys were present, and whether the model was invalid if the due date or the checkout date were absent.
Describe a set of positive and negative test cases you implemented for a controller. The controller tests for the movies#show method check to see if the correct movie is returned when a valid id is given and whether an error message is returned when an invalid id is given.
How does your API respond when bad data is sent to it? Our API returns a json-formatted error message
Describe one of your custom model methods and why you chose to wrap that functionality into a method. One custom method we wrote was to determine the number of copies of a movie still available. We chose to wrap this functionality into a method because the data manipulation required to get that number seemed too complex for a controller method.
Do you have any recommendations on how we could improve this project for the next cohort?
Link to Trello We didn't use trello since we pair programmed the entire thing and worked side by side for the whole project.
Link to ERD https://drive.google.com/file/d/1XqHYUY1_8WM4SjMFXJmYL7wMj63NLT28/view?usp=sharing
Summary

@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 inline
All required endpoints return expected JSON data yes
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 mostly - see inline
Controller Tests - URI parameters and data in the request body have positive & negative cases mostly - see inline
Overall Good job overall. The big place where I see room for improvement is around identifying failure and edge cases, both for controllers and models. Fortunately we'll have plenty of opportunity to practice this once we get into React. Other than that I like what I see - keep up the hard work!

def index
customers = Customer.all.map { |customer| customer.as_json(only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone]).merge({ "movies_checked_out_count": customer.checked_out_count }) }
render status: :ok, json: customers.as_json
end

Choose a reason for hiding this comment

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

I would definitely encourage you to split line 3 up. Most style guides encourage no more than 80 characters on a line.


def customer_params
params.permit(:name, :registered_at, :address, :city, :state, :postal_code, :phone)
end

Choose a reason for hiding this comment

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

I don't think this method is ever used.

rental = Rental.new(movie_id: params[:movie_id],
customer_id: params[:customer_id],
checkout: DateTime.now,
due: DateTime.now + 7.days)

Choose a reason for hiding this comment

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

This code is pretty concise, but it might work even better as a model method, something like:

Rental.check_out(movie_id, customer_id)

That means you don't need the date logic here in the controller, and that you could include some targeted model testing for it.


def checked_out_count
return self.rentals.select { |rental| !rental.returned }.count
end

Choose a reason for hiding this comment

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

I love that you made Customer#checked_out_count and Movie#number_available methods instead of storing them in the database. That way there's no way to forget to update these values.

describe "checkout" do
it "customer can checkout and create a new rental" do
expect {
post checkout_path, params: @params

Choose a reason for hiding this comment

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

Are there some failure cases you could cover here? What if that movie isn't available?

describe "checkin" do
it "customer can checkin a rental" do
post checkout_path, params: @params

Choose a reason for hiding this comment

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

What if no outstanding rental exists for that customer / movie?


it "can return the number currently available" do
expect(movie.number_available).must_equal 0
end

Choose a reason for hiding this comment

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

I would also like to see that this works when there are some movies available

it "can return the number of movies currently checked out" do
expect(customer.checked_out_count).must_equal 1
end
end

Choose a reason for hiding this comment

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

I would stick this in a separate describe. There might be an interesting edge case if there are no movies checked out.

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