diff --git a/.gitignore b/.gitignore index e16dc71d2..96c635955 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ # Ignore master key for decrypting credentials and more. /config/master.key + + +# Ignore coverage +/coverage \ No newline at end of file diff --git a/.rspec b/.rspec new file mode 100644 index 000000000..c99d2e739 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..2aca9d06e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +Style/FrozenStringLiteralComment: + Enabled: false + +Metrics/BlockLength: + IgnoredMethods: + - RSpec.describe \ No newline at end of file diff --git a/Gemfile b/Gemfile index a8a68a722..193a00601 100644 --- a/Gemfile +++ b/Gemfile @@ -1,31 +1,33 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.2.2" +ruby '3.2.2' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.0.4", ">= 7.0.4.2" +gem 'rails', '~> 7.0.4', '>= 7.0.4.2' # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] -gem "sprockets-rails" +gem 'sprockets-rails' # Use postgresql as the database for Active Record -gem "pg", "~> 1.1" +gem 'pg', '~> 1.1' # Use the Puma web server [https://github.com/puma/puma] -gem "puma", "~> 5.0" +gem 'puma', '~> 5.0' # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] -gem "importmap-rails" +gem 'importmap-rails' # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem "turbo-rails" +gem 'turbo-rails' # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] -gem "stimulus-rails" +gem 'stimulus-rails' # Build JSON APIs with ease [https://github.com/rails/jbuilder] -gem "jbuilder" +gem 'jbuilder' # Use Redis adapter to run Action Cable in production # gem "redis", "~> 4.0" @@ -34,13 +36,13 @@ gem "jbuilder" # gem "kredis" # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" +gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] # Reduces boot times through caching; required in config/boot.rb -gem "bootsnap", require: false +gem 'bootsnap', require: false # Use Sass to process CSS # gem "sassc-rails" @@ -48,26 +50,33 @@ gem "bootsnap", require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" +gem 'faraday' + group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem "pry" + gem 'factory_bot_rails' + gem 'faker' + gem 'pry' + gem 'rspec-rails' end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] - gem "web-console" + gem 'web-console' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler" # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" - gem "rubocop-rails" + gem 'rubocop-rails' end group :test do - gem "rspec-rails" - gem "capybara" - gem "launchy" - gem "simplecov" -end \ No newline at end of file + gem 'capybara' + gem 'launchy' + gem 'shoulda-matchers' + gem 'simplecov' + gem 'vcr' + gem 'webmock' +end diff --git a/Gemfile.lock b/Gemfile.lock index b54ee32ad..e8b393560 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,76 +1,78 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.6) - actionpack (= 7.0.6) - activesupport (= 7.0.6) + actioncable (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.6) - actionpack (= 7.0.6) - activejob (= 7.0.6) - activerecord (= 7.0.6) - activestorage (= 7.0.6) - activesupport (= 7.0.6) + actionmailbox (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.6) - actionpack (= 7.0.6) - actionview (= 7.0.6) - activejob (= 7.0.6) - activesupport (= 7.0.6) + actionmailer (7.0.8) + actionpack (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activesupport (= 7.0.8) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.6) - actionview (= 7.0.6) - activesupport (= 7.0.6) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.6) - actionpack (= 7.0.6) - activerecord (= 7.0.6) - activestorage (= 7.0.6) - activesupport (= 7.0.6) + actiontext (7.0.8) + actionpack (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.6) - activesupport (= 7.0.6) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.6) - activesupport (= 7.0.6) + activejob (7.0.8) + activesupport (= 7.0.8) globalid (>= 0.3.6) - activemodel (7.0.6) - activesupport (= 7.0.6) - activerecord (7.0.6) - activemodel (= 7.0.6) - activesupport (= 7.0.6) - activestorage (7.0.6) - actionpack (= 7.0.6) - activejob (= 7.0.6) - activerecord (= 7.0.6) - activesupport (= 7.0.6) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activestorage (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activesupport (= 7.0.8) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.6) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.4) + addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) + base64 (0.2.0) + bcrypt (3.1.20) bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.17.0) msgpack (~> 1.2) builder (3.2.4) capybara (3.39.2) @@ -84,26 +86,42 @@ GEM xpath (~> 3.2) coderay (1.1.3) concurrent-ruby (1.2.2) + crack (0.4.5) + rexml crass (1.0.6) - date (3.3.3) + date (3.3.4) diff-lcs (1.5.0) docile (1.4.0) erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) + factory_bot (6.4.2) + activesupport (>= 5.0.0) + factory_bot_rails (6.4.2) + factory_bot (~> 6.4) + railties (>= 5.0.0) + faker (3.2.2) + i18n (>= 1.8.11, < 2) + faraday (2.7.12) + base64 + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) + globalid (1.2.1) + activesupport (>= 6.1) + hashdiff (1.0.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - importmap-rails (1.2.1) + importmap-rails (1.2.3) actionpack (>= 6.0.0) + activesupport (>= 6.0.0) railties (>= 6.0.0) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) - json (2.6.3) + json (2.7.0) language_server-protocol (3.17.0.3) launchy (2.5.2) addressable (~> 2.8) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -114,79 +132,77 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.18.1) - msgpack (1.7.1) - net-imap (0.3.6) + mini_mime (1.1.5) + minitest (5.20.0) + msgpack (1.7.2) + net-imap (0.4.7) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.4.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.2-arm64-darwin) - racc (~> 1.4) - nokogiri (1.15.2-x86_64-darwin) + nio4r (2.7.0) + nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) parallel (1.23.0) - parser (3.2.2.3) + parser (3.2.2.4) ast (~> 2.4.1) racc - pg (1.5.3) + pg (1.5.4) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - public_suffix (5.0.1) - puma (5.6.6) + public_suffix (5.0.4) + puma (5.6.7) nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.7) + racc (1.7.3) + rack (2.2.8) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.6) - actioncable (= 7.0.6) - actionmailbox (= 7.0.6) - actionmailer (= 7.0.6) - actionpack (= 7.0.6) - actiontext (= 7.0.6) - actionview (= 7.0.6) - activejob (= 7.0.6) - activemodel (= 7.0.6) - activerecord (= 7.0.6) - activestorage (= 7.0.6) - activesupport (= 7.0.6) + rails (7.0.8) + actioncable (= 7.0.8) + actionmailbox (= 7.0.8) + actionmailer (= 7.0.8) + actionpack (= 7.0.8) + actiontext (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activemodel (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) bundler (>= 1.15.0) - railties (= 7.0.6) - rails-dom-testing (2.1.1) + railties (= 7.0.8) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.6) - actionpack (= 7.0.6) - activesupport (= 7.0.6) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.8.1) - rexml (3.2.5) + rake (13.1.0) + regexp_parser (2.8.2) + rexml (3.2.6) rspec-core (3.12.2) rspec-support (~> 3.12.0) rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.5) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-rails (6.0.3) + rspec-rails (6.1.0) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) @@ -195,67 +211,80 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - rubocop (1.54.0) + rubocop (1.58.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) + rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-rails (2.20.2) + rubocop-rails (2.22.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + shoulda-matchers (5.3.0) + activesupport (>= 5.2.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - stimulus-rails (1.2.1) + stimulus-rails (1.3.0) railties (>= 6.0.0) - thor (1.2.2) - timeout (0.4.0) - turbo-rails (1.4.0) + thor (1.3.0) + timeout (0.4.1) + turbo-rails (1.5.0) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) - web-console (4.2.0) + unicode-display_width (2.5.0) + vcr (6.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - websocket-driver (0.7.5) + webmock (3.19.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.8) + zeitwerk (2.6.12) PLATFORMS - arm64-darwin-22 - x86_64-darwin-21 + arm64-darwin-21 + arm64-darwin-23 DEPENDENCIES + bcrypt (~> 3.1.7) bootsnap capybara + factory_bot_rails + faker + faraday importmap-rails jbuilder launchy @@ -265,15 +294,18 @@ DEPENDENCIES rails (~> 7.0.4, >= 7.0.4.2) rspec-rails rubocop-rails + shoulda-matchers simplecov sprockets-rails stimulus-rails turbo-rails tzinfo-data + vcr web-console + webmock RUBY VERSION ruby 3.2.2p53 BUNDLED WITH - 2.3.26 + 2.4.19 diff --git a/Rakefile b/Rakefile index 9a5ea7383..488c551fe 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d67269728..9aec23053 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442f4..8d6c2a1bf 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12a..6604071b8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,9 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base + helper_method :current_user + + def current_user + current_user ||= User.find(session[:user_id]) if session[:user_id] + end end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 000000000..5ce96384f --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,15 @@ +class MoviesController < ApplicationController + def index + @movies = if params[:q] == 'top-rated' + MovieFacade.top_rated + else + MovieFacade.search(params[:search]) + end + end + + def show + @movie_info = MovieFacade.movie_details(params[:movie_id]) + @cast = MovieFacade.cast(params[:movie_id]) + @reviews = MovieFacade.reviews(params[:movie_id]) + end +end diff --git a/app/controllers/users/discover_controller.rb b/app/controllers/users/discover_controller.rb new file mode 100644 index 000000000..1665398c4 --- /dev/null +++ b/app/controllers/users/discover_controller.rb @@ -0,0 +1,6 @@ +module Users + class DiscoverController < ApplicationController + def index + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..df1bcb012 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,65 @@ +class UsersController < ApplicationController + + def index + @users = User.all + end + + def show + if current_user + @movie_info = current_user.my_movies + if @movie_info != [] + @image = @movie_info.first.image_url + end + else + redirect_to root_path + flash[:alert] = "You must be logged in or registered to access the dashboard." + end + end + + def new + @user = User.new + end + + def create + user = User.new(user_params) + + if user.save + session[:user_id] = user.id + redirect_to user_dashboard_path(user) + else + flash[:alert] = 'Error: Please fill out all fields and use a unique email' + render :new + end + require 'pry'; binding.pry + end + + def login_form + end + + def login_user + user = User.find_by(name: params[:username]) + + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + flash[:success] = "Welcome, #{user.name}!" + redirect_to user_dashboard_path(user) + elsif !user + flash[:error] = "We could not find your account. Register an account or try again." + redirect_to login_path + elsif params[:password] != user.password + flash[:error] = "Your password is incorrect. Try again." + redirect_to login_path + end + end + + def logout + session.clear + redirect_to root_path + end + + private + + def user_params + params.require(:user).permit(:name, :email, :password) + end +end diff --git a/app/controllers/viewing_parties_controller.rb b/app/controllers/viewing_parties_controller.rb new file mode 100644 index 000000000..76eaa44ef --- /dev/null +++ b/app/controllers/viewing_parties_controller.rb @@ -0,0 +1,48 @@ +class ViewingPartiesController < ApplicationController + def new + @movie_runtime = params[:movie_runtime] + @movie_title = params[:movie_title] + @movie_id = params[:movie_id] + @users = User.all + + if current_user + @user = current_user + else + redirect_to movie_show_path(params[:movie_id]) + flash[:errors] = "You must be logged in or registered to create a viewing party." + end + end + + def create + @user = User.find(params[:id]) + @attendees = params[:user_ids] + + viewing_party_params = { + party_duration: params[:party_duration], + start_time: params[:start_time], + movie_title: params[:movie_title], + movie_id: params[:movie_id], + host_id: @user.id + } + + @viewing_party = ViewingParty.create!(viewing_party_params) + + @viewing_party.add_attendees(@attendees) + + # adds in the user who created the viewing party + @viewing_party.users << @user + + # find the host in the UserViewingParty table + @user_viewing_party = UserViewingParty.find_by(user_id: @user.id, viewing_party_id: @viewing_party.id) + + @user_viewing_party&.update(host: true) + + if @viewing_party.save + flash[:alert] = 'Viewing Party Created!' + redirect_to user_dashboard_path(@user.id) + else + flash[:alert] = 'Error: Please fill out all fields' + render :new + end + end +end diff --git a/app/facades/movie_facade.rb b/app/facades/movie_facade.rb new file mode 100644 index 000000000..23229d6ee --- /dev/null +++ b/app/facades/movie_facade.rb @@ -0,0 +1,34 @@ +class MovieFacade + def self.top_rated + json_response = MovieService.top_rated + json_response[:results].map do |movie| + Movie.new(movie) + end.first(20) + end + + def self.search(search_term) + json_response = MovieService.search(search_term) + json_response[:results].map do |movie| + Movie.new(movie) + end.first(20) + end + + def self.movie_details(movie) + json_response = MovieService.movie_details(movie) + Movie.new(json_response) + end + + def self.cast(movie) + json_response = MovieService.cast(movie) + json_response[:cast].map do |cast| + Cast.new(cast) + end.first(10) + end + + def self.reviews(movie) + json_response = MovieService.reviews(movie) + json_response[:results].map do |result| + Review.new(result) + end.first(10) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..15b06f0f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d10..bef395997 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 3c34c8148..d84cb6e71 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base - default from: "from@example.com" - layout "mailer" + default from: 'from@example.com' + layout 'mailer' end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index b63caeb8a..08dc53798 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..3cf4f5bbf --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class User < ApplicationRecord + has_many :user_viewing_parties + has_many :viewing_parties, through: :user_viewing_parties + + validates :name, presence: true + validates :email, presence: true, uniqueness: true + validates :password, presence: true + + has_secure_password + + def my_movies + movies = [] + viewing_parties.uniq.each do |party| + movies << MovieFacade.movie_details(party.movie_id) + movies << MovieFacade.cast(party.movie_id) + movies << MovieFacade.reviews(party.movie_id) + end + movies + end +end diff --git a/app/models/user_viewing_party.rb b/app/models/user_viewing_party.rb new file mode 100644 index 000000000..1d57ee7d2 --- /dev/null +++ b/app/models/user_viewing_party.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class UserViewingParty < ApplicationRecord + belongs_to :user + belongs_to :viewing_party + + validates :user_id, :viewing_party_id, presence: true +end diff --git a/app/models/viewing_party.rb b/app/models/viewing_party.rb new file mode 100644 index 000000000..6320ff803 --- /dev/null +++ b/app/models/viewing_party.rb @@ -0,0 +1,16 @@ +class ViewingParty < ApplicationRecord + has_many :user_viewing_parties + has_many :users, through: :user_viewing_parties + + validates :party_duration, :start_time, :movie_title, :movie_id, presence: true + + def add_attendees(attendees) + # goes through the params[:user_ids] (which is everyone who is checked off), + # find the user related to that user_id, and add them to the VP.users + return if attendees.nil? + + attendees.each do |id| + users << User.find_by(id:) + end + end +end diff --git a/app/poros/cast.rb b/app/poros/cast.rb new file mode 100644 index 000000000..1db05da41 --- /dev/null +++ b/app/poros/cast.rb @@ -0,0 +1,9 @@ +class Cast + attr_reader :name, + :character + + def initialize(attributes) + @name = attributes[:name] + @character = attributes[:character] + end +end diff --git a/app/poros/movie.rb b/app/poros/movie.rb new file mode 100644 index 000000000..99f48ec49 --- /dev/null +++ b/app/poros/movie.rb @@ -0,0 +1,30 @@ +class Movie + attr_reader :movie_id, + :title, + :vote_average, + :runtime, + :genre, + :overview, + :cast, + :vote_count, + :review_info, + :image_url + + def initialize(attributes) + @movie_id = attributes[:id] + @title = attributes[:title] + @vote_average = attributes[:vote_average] + @runtime = attributes[:runtime] + @genre = attributes[:genres] + @overview = attributes[:overview] + @vote_count = attributes[:vote_count] + @image_url = attributes[:poster_path] + end + + def convert_runtime_to_hours_and_minutes + hours = @runtime / 60 + remaining_minutes = @runtime % 60 + + "#{hours} hours and #{remaining_minutes} minutes" + end +end diff --git a/app/poros/review.rb b/app/poros/review.rb new file mode 100644 index 000000000..3bbc49340 --- /dev/null +++ b/app/poros/review.rb @@ -0,0 +1,9 @@ +class Review + attr_reader :author, + :content + + def initialize(attributes) + @author = attributes[:author] + @content = attributes[:content] + end +end diff --git a/app/services/movie_service.rb b/app/services/movie_service.rb new file mode 100644 index 000000000..8c1654126 --- /dev/null +++ b/app/services/movie_service.rb @@ -0,0 +1,32 @@ +class MovieService + def self.conn + Faraday.new(url: 'https://api.themoviedb.org') do |faraday| + faraday.params['api_key'] = Rails.application.credentials.TMDB[:key] + end + end + + def self.get_url(url) + response = conn.get(url) + JSON.parse(response.body, symbolize_names: true) + end + + def self.top_rated + get_url('/3/movie/top_rated') + end + + def self.search(search_term) + get_url("/3/search/movie?query=#{search_term}") + end + + def self.movie_details(movie_id) + get_url("/3/movie/#{movie_id}") + end + + def self.cast(movie_id) + get_url("/3/movie/#{movie_id}/credits") + end + + def self.reviews(movie_id) + get_url("/3/movie/#{movie_id}/reviews") + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 552042a39..a631c75d2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,9 +8,23 @@ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> + + <% if !current_user %> + <%= link_to "New User", register_path, method: :get %> + <%= link_to "Log In", login_path, method: :get %> + <% elsif current_user %> + <%= link_to "Log Out", logout_path, method: :get %> + <% end %> +
+ <% flash.each do |type, message| %> +<%= message %>
+ <% end %> + + <%= yield %>