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

Ari & Luxi - VideoStoreConsumer-API - Octos #14

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gem 'will_paginate'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'dotenv-rails'
end

group :development do
Expand All @@ -56,8 +57,6 @@ group :development do

# Use pry for rails console
gem 'pry-rails'

gem 'dotenv-rails'
end

group :test do
Expand All @@ -71,3 +70,5 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'httparty'

gem "active_model_serializers"

gem 'rack-cors', require: 'rack/cors'
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ GEM
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
puma (3.6.2)
puma (3.11.4)
rack (2.0.1)
rack-cors (1.0.2)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.1)
Expand Down Expand Up @@ -210,6 +211,7 @@ DEPENDENCIES
minitest-spec-rails
pry-rails
puma (~> 3.0)
rack-cors
rails (~> 5.0.1)
sass-rails (~> 5.0)
spring
Expand Down
16 changes: 15 additions & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ def index
else
data = Movie.all
end

render status: :ok, json: data
end

def create
movie = Movie.new(movie_params)
if movie.save
render json: movie.as_json(except: [:created_at, :updated_at], status: :ok)
else
render json: { errors: movie.errors.messages }, status: :bad_request
end
end

def show
render(
status: :ok,
Expand All @@ -23,6 +31,12 @@ def show

private

def movie_params
# return params.permit(:title, :overview, :release_date, :image_url, :external_id)

return params.permit(:title, :overview, :release_date, :image_url, :external_id, :inventory)
end

def require_movie
@movie = Movie.find_by(title: params[:title])
unless @movie
Expand Down
1 change: 1 addition & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class RentalsController < ApplicationController
def check_out
rental = Rental.new(movie: @movie, customer: @customer, due_date: params[:due_date])

rental.returned = false
if rental.save
render status: :ok, json: {}
else
Expand Down
10 changes: 6 additions & 4 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class Application < Rails::Application
#this loads everything in the lib folder automatically
config.eager_load_paths << Rails.root.join('lib')

config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => %w{GET POST OPTIONS}.join(",")
}
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :patch, :delete, :options]
end
end
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

resources :customers, only: [:index]

resources :movies, only: [:index, :show], param: :title
resources :movies, only: [:index, :create, :show], param: :title

post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out"
post "/rentals/:title/return", to: "rentals#check_in", as: "check_in"
Expand Down
24 changes: 0 additions & 24 deletions package.json

This file was deleted.