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

Lily & Phoebe - Ampers #3

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@
# Ignore Byebug command history file.
.byebug_history
.env

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
16 changes: 15 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end



group :development, :test do
gem 'sqlite3'
end

group :production do
gem 'pg', '~> 0.18'
end

gem 'awesome_print'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
Expand All @@ -35,13 +45,17 @@ gem 'jbuilder', '~> 2.5'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'rack-cors', require: 'rack/cors'

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
end



group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ GEM
nio4r (1.2.1)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
pg (0.21.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
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 @@ -208,8 +210,10 @@ DEPENDENCIES
listen (~> 3.0.5)
minitest-reporters
minitest-spec-rails
pg (~> 0.18)
pry-rails
puma (~> 3.0)
rack-cors
rails (~> 5.0.1)
sass-rails (~> 5.0)
spring
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def index
if @sort
data = Customer.all.order(@sort)
else
data = Customer.all
data = Customer.order(:name)
end

data = data.paginate(page: params[:p], per_page: params[:n])
# data = data.paginate(page: params[:p], per_page: params[:n])

render json: data.as_json(
only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone, :account_credit],
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 @@ -5,7 +5,7 @@ def index
if params[:query]
data = MovieWrapper.search(params[:query])
else
data = Movie.all
data = Movie.order(:title)
end

render status: :ok, json: data
Expand All @@ -21,6 +21,16 @@ def show
)
end

def create
movie = Movie.new(movie_params)

if movie.save
render :json => movie.to_json, :status => :ok
else
render :json => { :errors=>movie.errors.messages }, :status => :bad_request
end
end

private

def require_movie
Expand All @@ -29,4 +39,8 @@ def require_movie
render status: :not_found, json: { errors: { title: ["No movie with title #{params["title"]}"] } }
end
end

def movie_params
return params.permit(:title, :overview, :release_date, :image_url, :external_id, :inventory)
end
end
8 changes: 7 additions & 1 deletion app/models/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ def image_url
if !orig_value
MovieWrapper::DEFAULT_IMG_URL
elsif external_id
MovieWrapper.construct_image_url(orig_value)
str = MovieWrapper.construct_image_url(orig_value)
index = str.rindex('https://image.tmdb.org/t/p/w185')
if index != 0
return str[index..-1]
else
return str
end
else
orig_value
end
Expand Down
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :options]
end
end

#this loads everything in the lib folder automatically
config.eager_load_paths << Rails.root.join('lib')
Expand Down
7 changes: 6 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ test:

production:
<<: *default
database: db/production.sqlite3
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
database: <APPLICATION_NAME>_production
username: <APPLICATION_NAME>
password: <%= ENV['<APPLICATION_NAME>_DATABASE_PASSWORD'] %>
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, :show, :create], 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