Skip to content

Lina - Earth, Blaine - Fire |Vid-Store-API|#21

Open
Blaine206 wants to merge 31 commits into
Ada-C14:masterfrom
Blaine206:master
Open

Lina - Earth, Blaine - Fire |Vid-Store-API|#21
Blaine206 wants to merge 31 commits into
Ada-C14:masterfrom
Blaine206:master

Conversation

@Blaine206

Copy link
Copy Markdown

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 Based on the seed data we knew there needed to be Video and Customer models. Reading further into the rentals endpoint data on wiki, we came to the conclusion that there should be a rentals model. This was because it did everything a join table did, relating the 2 other models, but also needed to track due dates. Lastly, we knew rentals needed business logic, which let us know a model was the best choice.
What would be the Big-O time complexity of your /customers & /videos endpoints? What does the time complexity depend on? Explain your reasoning. We believe the Big O is O(n^2). It depends on the index method- we initially call on the .all method, then the .order method, both of which iterate and produce a list of all the videos/customers. Because the lengths of the lists can vary we equate that to 'n' and since it's iterated over twice with both the .all & .order methods, we agreed on O(n^2).
What is the Big-O time complexity of the POST /rentals/check-in endpoint? What does the time complexity depend on? Explain your reasoning. We believe the Big-O is an O(n), because of the .find_by enumerable.
Describe a specific set of positive and negative test cases you implemented for a model. Pos: Checked video is valid with all required fields Neg:Checked video is invalid if any of the required fields had bad data
Describe a specific set of positive and negative test cases you implemented for a controller. Neg: Would respond with a 404 for an invalid video id Pos: Can create a valid rental for the checkout action
Broadly, describe how an API should respond when it handles a request with invalid/erroneous parameters. It should respond with a 404 :not_found or 400 :bad_request and an error message in the body.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We created a .increase_customer_video_count method. Placed it in the model cause it was a helper, with business logic, and cleaned up the code (DRY) keeping the controller nice and pretty.

Blaine206 and others added 30 commits December 2, 2020 09:48
…dated checkout action method to update inventory/update video count/ add duedate

@dHelmgren dHelmgren left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +7 to +34
if existing_customer.nil? || existing_video.nil?
render json: {
errors: ['Not Found']
}, status: :not_found
return
elsif existing_video.available_inventory <= 0
render json: {
errors: ['Bad Request']
}, status: :bad_request
return
end

rental = Rental.new(rental_params)

# create a new rental
if rental.save

rental.increase_customer_video_count
rental.decrease_available_video_inventory
rental.return_date

customer = Customer.find_by(id: existing_customer.id)
video = Video.find_by(id: existing_video.id)

render json: {
customer_id: rental.customer_id,
video_id: rental.video_id,
due_date: rental.due_date,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is the business logic! Instead of breaking out small chunks to the model, put the whole of this action into the model!

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