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

Octos - VideoStoreAPI - Brandy and Jamila #16

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'rack-cors', require: 'rack/cors'

# Use jquery as the JavaScript library
gem 'jquery-rails'
Expand Down
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
10 changes: 10 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ def show
)
end

def create
movie = Movie.new(title: params["title"], overview: params["overview"], release_date: params["release_date"], image_url: params["image_url"])

movie.save
end

private

# def movie_params
# return params.permit(title: params["title"], overview: params["overview"], release_date: params["release_date"], image_url: params["image_url"])
# end

def require_movie
@movie = Movie.find_by(title: params[:title])
unless @movie
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, :options]
end
end
end
end
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

resources :customers, only: [:index]

resources :movies, only: [:index, :show], param: :title
resources :movies, only: [:index, :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"
get "/rentals/overdue", to: "rentals#overdue", as: "overdue"

post "/movies", to: "movies#create", as: "create"

end
5 changes: 5 additions & 0 deletions db/migrate/20180620223521_add_inlibary_flag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInlibaryFlag < ActiveRecord::Migration[5.0]
def change
add_column :movies, :in_library, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180618042754) do
ActiveRecord::Schema.define(version: 20180620223521) do

create_table "customers", force: :cascade do |t|
t.string "name"
Expand All @@ -34,6 +34,7 @@
t.datetime "updated_at", null: false
t.string "image_url"
t.integer "external_id"
t.boolean "in_library"
end

create_table "rentals", force: :cascade do |t|
Expand Down
10 changes: 10 additions & 0 deletions lib/movie_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def self.search(query)
end
end

# def self.details(title)
# puts "here we are"
# url = BASE_URL + "search/movie?api_key=" + KEY + "&query=" + title
# response = HTTParty.get(url)
# puts response
#
# return response
#
# end

private

def self.construct_movie(api_result)
Expand Down
9 changes: 9 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- only one change to the API...it needs to add movies to the rental library (which is in its local database, not the external API) when the user clicks the "add to library" button on the search results page

- the search results page queries the external api after going through a route that is in our api wrapper...only some of the possible movies are currently in the rental library as the seeds file does not add everything

- the seeds file creates the rental library with the help of the external api, the title is the only item that is used from the movies.json file, the inventory is not involved anywhere...it is meaningless...we can assume there is endless inventory

- only functionality of the app is that you can search for a movie, view the rental library, select movie and customer which is info that's stored until a controlled form is submitted

- the controlled form sends a post request to our api wrapper which records the checkout though there is no get request for this so the information can't be viewed anywhere