Skip to content

Conversation

@angethuy
Copy link

Assignment Submission: Video Store API

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

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.

Reflection

Prompt Response
Explain how you came up with the initial design of your ERD, based on the seed data and reading through the API endpoints The seed data gave us an idea of what the columns of our database entities should be. The API endpoint descriptions indicated which actions would likely show up in their respective controllers. The nesting structure of the rentals endpoints was particularly indicative that check-in/check-out actions belonged to the Rentals controller.
What would be the Big-O time complexity of your /customers & /videos endpoints? What does the time complexity depend on? Explain your reasoning. Index retrieves and returns all respective records in order, so depending on how the ordering is done, time complexity could be O(n log n) where n is the number of records. The "create" actions insert a record into the database, which seems like a O(1) operation.
What is the Big-O time complexity of the POST /rentals/check-in endpoint? What does the time complexity depend on? Explain your reasoning. In order to check in a valid rental, we had to first confirm it exists in the database by running find_by on three separate columns (customer_id, video_id, returned_on). Since these fields are hash keys, look-up on them should be O(1)
Describe a specific set of positive and negative test cases you implemented for a model. We only tested validations on our models. In our Customer model, we tested the success case (all required fields available), and we tested all possible invalid cases (each attribute missing).
Describe a specific set of positive and negative test cases you implemented for a controller. In our Rentals controller, we tested to confirm that we could 1) checkout a Rental on a video that had inventory available, and 2) fail to checkout a Rental on a video that had zero inventory available.
Broadly, describe how an API should respond when it handles a request with invalid/erroneous parameters. The API should return a header containing the error's HTTP response code and hopefully a helpful explanation of why it went badly.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We made "available_inventory" a method on our Video model because we attempted to derive data off existing fields whenever possible and decided that available_inventory could be found by counting that Video's associated Rental objects.

Copy link

@kaidamasaki kaidamasaki left a comment

Choose a reason for hiding this comment

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

Excellent job! Your code is of extremely high quality and I've really only got minor suggestions for improvement.

def index
@customers = Customer.order(:name)
render json: @customers.to_json(
:only => [:id, :name, :registered_at, :postal_code, :phone], :methods => [:videos_checked_out_count]), status: :ok

Choose a reason for hiding this comment

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

Great job using :methods here!

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

def videos_checked_out_count
return self.rentals.where(returned_on: nil).count

Choose a reason for hiding this comment

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

I'm impressed that you did all of this with Active Record methods instead of falling back on select and length!

Comment on lines +18 to +22
def valid_availability
if total_inventory.nil?
errors.add(:available_inventory, "bad data error")
end
end

Choose a reason for hiding this comment

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

This is redundant with the presence: true for total_inventory.

belongs_to :video
belongs_to :customer

validate :inventory_available, on: :create

Choose a reason for hiding this comment

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

This could have been replaced with:

Suggested change
validate :inventory_available, on: :create
validates :available_inventory, numericality: { greater_than: 0 }

@kaidamasaki
Copy link

Video Store API

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Practices git with at least 10 small commits and meaningful commit messages ✔️
Understands the importance of how APIs handle invalid/erroneous data in their reflection questions ✔️
Practices Rails best practices and well-designed separation, and encapsulates business logic around check-out and check-in in models ✔️
Uses controller tests to ensure quality code for every route, and checks for response status and content, with positive cases and negative cases ✔️
Uses controller tests to ensure correctness for check out and check in requirement, and that checked out counts and inventories appropriately change ✔️

Functional Requirements

Functional Requirement yes/no
All provided smoke tests for Wave 1 pass ✔️
All provided smoke tests for Wave 2 pass ✔️

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 3+ in Code Review && 2 in Functional Requirements ✔️
Yellow (Approaches Standards) 2+ in Code Review && 1+ in Functional Requirements, or the instructor judges that this project needs special attention
Red (Not at Standard) 0-1 in Code Review or 0 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging, or the instructor judges that this project needs special attention

Comprehension Questions

These are just for your learning and aren't something you're graded on:

Index retrieves and returns all respective records in order, so depending on how the ordering is done, time complexity could be O(n log n) where n is the number of records.

If you're sorting by something with an index (like the id) this will actually be O(n) because of database optimizations.

In order to check in a valid rental, we had to first confirm it exists in the database by running find_by on three separate columns (customer_id, video_id, returned_on). Since these fields are hash keys, look-up on them should be O(1)

The lookup here is going to be O(log(n)) because the find_by has to use the database indexes. (O(log(n)) is very fast though so is not something I would worry about.)

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever
Descriptive/Readable
Concise
Logical/Organized

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