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

Amy & Christiane -- Carets #20

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

Amy & Christiane -- Carets #20

wants to merge 45 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Nov 9, 2017

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 looked at the seed data and identified two classes: Customer and Movie, and determined that they had a many to many relationship that we decided to implement as a many through Rental relationship
Describe a set of positive and negative test cases you implemented for a model. We test that the release_date of a new movie is present and in the right format. As a positive test we check that a new movie is created given all the right input.
Describe a set of positive and negative test cases you implemented for a controller. A positive test case is that customer#index return all the right fields and only the right fields for all customers. A negative test we have is that when we fail to find a movie we send back an error message.
How does your API respond when bad data is sent to it? If any required inputs are missing, we return a JSON hash, with an error message and a status of bad_request.
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We made a Customer#overdue_rentals method that returns an array of all Rentals that belong to a customer and are overdue: We built this to use in our Customer#overdue method, which returns an array of hashes; where each hash corresponds to a customer that has an overdue rental, with their associated customer information and an array of all of their overdue Rentals.
Do you have any recommendations on how we could improve this project for the next cohort? We spent a lot of time talking about the design of the check_in and the use of a POST method instead of PATCH and using the given route instead of a nested route including the rental_id. Some insight into why the POST verb and the unnested route were used instead of a PATCH route to update a specific Rental would have been nice.
Link to Trello https://trello.com/b/3p9XeJ1i/video-store-api
Link to ERD Done on paper

ayjlee and others added 30 commits November 6, 2017 12:39
@CheezItMan
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Good number of commit and good commit messages, both team members participated
Comprehension questions Check, noted on the post routes
General
Business Logic in Models Some, but you have a lot of code in the controllers which should be in the models.
All 3 required endpoints return expected JSON data Some problems with /movies and /customers
Requests respond with appropriate HTTP Status Code Check, once place where you returned 201 instead of 200, but that's ok.
Errors are reported Some, other places if there's an error it just crashes.
Testing
Passes all Smoke Tests Nope! get customer list fails!
Model Tests - all relations, validations, and custom functions test positive & negative cases No tests for Rental!!!
Controller Tests - URI parameters and data in the request body have positive & negative cases Good negative tests here
Optionals
POST routes use URI parameter and request body to add a new record to the database Check
GET /customers shows how many movies are checked out by a customer Missing!
GET /movies/:id shows updated inventory Yes... if I update the seeds file to include available_inventory or you make sure all models start with the field set.
Overall There's some real issues here, I wasn't expecting this. I think you should have turned in a more solid product. Did you forget to merge a branch?

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Some comments

movie = Movie.find_by_id(params[:movie_id])
customer = Customer.find_by_id(params[:customer_id])

unless movie.available_inventory > 0

Choose a reason for hiding this comment

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

What if movie is nil??

I notice the seeds file has all the movies started off with nil for available inventory, when I ran this locally.

@@ -0,0 +1,3 @@
class MovieSerializer < ActiveModel::Serializer
attributes :title, :overview, :release_date, :inventory, :available_inventory

Choose a reason for hiding this comment

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

id field???

@@ -0,0 +1,59 @@
class CustomersController < ApplicationController
def index
customers = Customer.all

Choose a reason for hiding this comment

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

Your customers don't have a count of the movies checked out!

def overdue
# overdue_rentals = Rental.where("movie_id = ? AND customer_id = ?", movie.id, customer.id)
# theoretical: has_overdue?
customers_with_overdue= Customer.all.select {|customer| customer.has_overdue?}

Choose a reason for hiding this comment

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

While this will work, it's usually better to let the database do a lot of the work, with some sort of where clause, probably in a class method of Customer which selects movies which are overdue.

The database is almost always faster about this.

@@ -0,0 +1,3 @@
class CustomerSerializer < ActiveModel::Serializer

Choose a reason for hiding this comment

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

Using Serializers, Neat!

@@ -0,0 +1,24 @@
class ApplicationController < ActionController::API

def build_overdue_array(rentals_array)

Choose a reason for hiding this comment

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

Why is this here? This looks like it should be in the model!

Come to think of it it looks like it is!


overdue_customers_array = []

customers_with_overdue.each do |customer|

Choose a reason for hiding this comment

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

This should really be in the model

render json: { ok: false, message: "No checked out copy of #{movie.title} for #{customer.name} found" }, status: :not_found
end

if checked_out.count > 0

Choose a reason for hiding this comment

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

Again this kind of functionality should go in the model.

@@ -0,0 +1,3 @@
class CustomerSerializer < ActiveModel::Serializer
attributes :registered_at, :name, :address, :city, :state, :postal_code, :phone, :movies_checked_out, :id

Choose a reason for hiding this comment

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

However no movies_checked_out_count

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.

2 participants