diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index be25f1be..b773ee79 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -18,6 +18,19 @@ def index ) end + def show + customer = Customer.find_by(id: params[:id]) + if customer + render json: customer.as_json( + only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone, :account_credit, :rentals], + methods: [:movies_checked_out_count], + include: [:rentals] + ) + else + render status: :bad_request, json: { errors: errors } + end + end + private def parse_query_args errors = {} diff --git a/config/routes.rb b/config/routes.rb index 8eff1ff6..f808027a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - resources :customers, only: [:index] + resources :customers, only: [:index, :show] resources :movies, only: [:index, :show, :create], param: :title