forked from turingschool-examples/viewing_party_lite_7
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from aevans27/discover-movies-page
Discover movies page
- Loading branch information
Showing
18 changed files
with
1,062 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class DiscoverController < ApplicationController | ||
def index | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class MoviesController < ApplicationController | ||
def index | ||
if params[:Movie_Title].present? | ||
facade = MovieFacade.new | ||
@results = facade.search_movies(params[:Movie_Title]) | ||
else | ||
facade = MovieFacade.new | ||
@results = facade.top_movies | ||
end | ||
end | ||
|
||
def show | ||
facade = MovieFacade.new | ||
@data = facade.movie_details(params[:id]) | ||
@data2 = facade.movie_cast(params[:id]) | ||
@data3 = facade.movie_reviews(params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class MovieFacade | ||
def top_movies | ||
service = MovieService.new | ||
data = service.top_movies[:results] | ||
limit = data[0..20] | ||
@results = limit.map do |movie_data| | ||
MoviePoro.new(movie_data) | ||
end | ||
end | ||
|
||
def search_movies(title) | ||
service = MovieService.new | ||
data = service.search_movies(title)[:results] | ||
limit = data[0..20] | ||
@results = limit.map do |movie_data| | ||
MoviePoro.new(movie_data) | ||
end | ||
end | ||
|
||
def movie_details(id) | ||
service = MovieService.new | ||
service.movie_details(id) | ||
end | ||
|
||
def movie_cast(id) | ||
service = MovieService.new | ||
service.movie_cast(id) | ||
end | ||
|
||
def movie_reviews(id) | ||
service = MovieService.new | ||
service.movie_reviews(id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class MoviePoro | ||
attr_reader :id, :title, :vote_average, :runtime, :genres, :overview, :cast, :results, :poster_path | ||
|
||
def initialize(data) | ||
@id = data[:id] | ||
@title = data[:title] | ||
@vote_average = data[:vote_average] | ||
@runtime = data[:runtime] | ||
@genres = data[:genres] | ||
@overview = data[:overview] | ||
@cast = data[:cast] | ||
@results = data[:results] | ||
@poster_path = data[:poster_path] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class MovieService | ||
def get_url(url) | ||
response = conn.get(url) | ||
JSON.parse(response.body, symbolize_names: true) | ||
end | ||
|
||
def top_movies | ||
get_url('/3/movie/popular') | ||
end | ||
|
||
def search_movies(title) | ||
get_url("/3/search/movie?query=#{title}") | ||
end | ||
|
||
def movie_details(id) | ||
get_url("/3/movie/#{id}") | ||
end | ||
|
||
def movie_cast(id) | ||
get_url("/3/movie/#{id}/credits") | ||
end | ||
|
||
def movie_reviews(id) | ||
get_url("/3/movie/#{id}/reviews") | ||
end | ||
|
||
def conn | ||
Faraday.new(url: "https://api.themoviedb.org") do |faraday| | ||
faraday.params['api_key'] = Rails.application.credentials.tmdb[:key] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= button_to 'Discover Top Rated Movies', "/users/#{params[:user_id]}/movies", method: :get %> | ||
|
||
<%= form_with url: "/users/#{params[:user_id]}/movies" , method: :get, local: true do |f| %> | ||
|
||
<%= f.label :Movie_Title %> | ||
<%= f.text_field :Movie_Title %> | ||
|
||
<%= f.submit 'Search by Movie Title' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Movie Results </h1> | ||
<% @results.each do |result| %> | ||
<ul class="movie_result"> | ||
<li><%= link_to "#{result.title}", "/users/#{params[:user_id]}/movies/#{result.id}" %></li> | ||
<li><%= result.vote_average %></li> | ||
</ul> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Discover Movies Page' do | ||
before(:each) do | ||
load_test_data | ||
end | ||
|
||
it 'When a user can get to movie results through movie title search' do | ||
|
||
visit "/users/#{@user1.id}/discover" | ||
|
||
expect(page).to have_button("Discover Top Rated Movies") | ||
expect(page).to have_button("Search by Movie Title") | ||
|
||
fill_in 'Movie_Title', with: "Batman" | ||
# click_button "Search by Movie Title" | ||
|
||
# expect(current_path).to eq("/users/#{@user1.id}/movies") | ||
end | ||
|
||
it 'When a user can get to movie results through top rated movies button' do | ||
|
||
visit "/users/#{@user1.id}/discover" | ||
|
||
expect(page).to have_button("Discover Top Rated Movies") | ||
expect(page).to have_button("Search by Movie Title") | ||
|
||
# click_button "Discover Top Rated Movies" | ||
|
||
# expect(current_path).to eq("/users/#{@user1.id}/movies") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Movie Results' do | ||
before(:each) do | ||
load_test_data | ||
end | ||
describe 'happy path' do | ||
it 'Get top 20 rated movies' do | ||
json_response = File.read('spec/fixtures/top_twenty_movies.json') | ||
stub_request(:get, "https://api.themoviedb.org/3/movie/popular?api_key=#{Rails.application.credentials.tmdb[:key]}"). | ||
with( | ||
headers: { | ||
'Accept'=>'*/*', | ||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'User-Agent'=>'Faraday v2.7.12' | ||
}). | ||
to_return(status: 200, body: json_response, headers: {}) | ||
|
||
visit "/users/#{@user1.id}/discover" | ||
|
||
expect(page).to have_button("Discover Top Rated Movies") | ||
expect(page).to have_button("Search by Movie Title") | ||
|
||
click_button "Discover Top Rated Movies" | ||
|
||
expect(page.status_code).to eq 200 | ||
|
||
expect(page).to have_link("Trolls Band Together") | ||
expect(page).to have_content(7.215) | ||
end | ||
|
||
it 'Get searched movies' do | ||
visit "/users/#{@user1.id}/discover" | ||
|
||
expect(page).to have_button("Discover Top Rated Movies") | ||
expect(page).to have_button("Search by Movie Title") | ||
|
||
json_response = File.read('spec/fixtures/batman_movies.json') | ||
stub_request(:get, "https://api.themoviedb.org/3/search/movie?api_key=#{Rails.application.credentials.tmdb[:key]}&query=Batman"). | ||
with( | ||
headers: { | ||
'Accept'=>'*/*', | ||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'User-Agent'=>'Faraday v2.7.12' | ||
}). | ||
to_return(status: 200, body: json_response, headers: {}) | ||
|
||
fill_in 'Movie_Title', with: "Batman" | ||
click_button "Search by Movie Title" | ||
|
||
expect(page.status_code).to eq 200 | ||
|
||
expect(page).to have_link("Batman Begins") | ||
expect(page).to have_content(7.2) | ||
end | ||
end | ||
end |
Empty file.
Oops, something went wrong.