diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 0000000000..7a18273272 --- /dev/null +++ b/.byebug_history @@ -0,0 +1,3 @@ +exit +!!! +n diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000000..bd4283f8bb --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,34 @@ +Neccesary checkmarks: + + [] All Tests are Passing + + [] The code will run locally + +Type of change + + [] New feature + [] Bug Fix + [] Refactor + +Implements/Fixes: + + description closes # + +Check the correct boxes + + [] This broke nothing + [] This broke some stuff + [] This broke everything + +Testing Changes + + [] No Tests have been changed + [] Some Tests have been changed + [] All of the Tests have been changed(Please describe what in the world happened) + +Checklist: + + [] My code has no unused/commented out code + [] I have reviewed my code + [] I have commented my code, particularly in hard-to-understand areas + [] I have fully tested my code diff --git a/.gitignore b/.gitignore index 655965c00c..b83861eba2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,9 +12,13 @@ /tmp/* !/log/.keep !/tmp/.keep - /node_modules /yarn-error.log # Ignore test coverage /coverage/* + +# sensative data +.env +# Ignore application configuration +/config/application.yml diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..37c2961c24 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.2 diff --git a/.travis.yml b/.travis.yml index 34c3c6fec3..a4c5ec8387 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rbenv: -- 2.5.3 +- 2.7.2 addons: postgresql: 9.6 script: @@ -8,6 +8,9 @@ script: - bundle exec rspec deploy: provider: heroku + api_key: - app: + secure: LUNR1EsF3qm7rOxPk8pqu9lltrphHB54ViLuuYu6nRnpYa4ef/9WDBklqzAyR2sQynDoUnqNufkF2HhJjP0BWfH/c8fDYhD7D37+9LrRo0ugwOjOAbQkrm4x36DxKbXHHDbiThiP5is+VMw3iQZu5DOPIup+uF1RXU0db7/XsfIlXtuCiBKqKTvhZYgDZvRL5GxxP3yu7YZaRf2un4a+L23iWPUWZi+CI4Aq6gxuTCkOfmGTSsFEaVdgDvNQU0EBag0wxkrHIJRREcngDrJPMOxwo0zP0Ta28k19QplFADgV/dBi3/E/scPQ+B0b04kWpGVymgaZo5wv4X86vpB4bYoiyiVtDHj4qr4ndHiMw01rprPkzVtj02HX1r7ko972NB3MXykyGzC3PZttcb0p5z5Jbm+2MhmVrBBegIXG+uSABkRxSq9KHvUc1jOzQCU6lfPj0BcBZFJB/ku7m6i7P2CAlOuvCY5F+NVYnD48mK7hepf9hKP+XSzrxRBii229oD5S+cW6EUqwOzN/mofNWxKWNHglJao+/BNqVxsXLjZRgUFH2sZQzstuzTegwjA25NobGxmq8FwRHf6kP93uif9lSd7fJjETqQ2vr7ntAJAf6bgyA+1x19Y9ccfE8JV1yhPSOq+6zh6lA4Vdr4x7/Qto6efO2+pOEkn3QJMSyng= + + app: viewing-party-turing run: rails db:migrate diff --git a/Gemfile b/Gemfile index 06343435c0..fb4a24c102 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,9 @@ end ruby '2.7.2' +gem 'figaro' + +gem 'dotenv-rails' gem 'rails', '5.2.5' gem 'pg', '>= 0.18', '< 2.0' gem 'puma', '~> 3.7' @@ -15,17 +18,19 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' gem 'bootsnap' gem 'jbuilder', '~> 2.5' +gem 'bcrypt', '~> 3.1.7' +gem 'jwt' group :development, :test do gem 'pry' gem 'travis' + gem 'byebug' end group :development do gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' gem 'rubocop-rails' - gem 'travis' end group :test do @@ -33,6 +38,11 @@ group :test do gem 'capybara' gem 'launchy' gem 'simplecov' + gem 'factory_bot_rails' + gem 'shoulda-matchers' + gem 'database_cleaner' + gem 'webmock' + gem 'vcr' end gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 1bb2bbcdfb..cc84d58553 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,10 +46,13 @@ GEM public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) ast (2.4.2) + bcrypt (3.1.16) + bcrypt (3.1.16-java) bindex (0.8.1) bootsnap (1.7.5) msgpack (~> 1.0) builder (3.2.4) + byebug (11.1.3) capybara (3.35.3) addressable mini_mime (>= 0.1.3) @@ -67,11 +70,28 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.8) + crack (0.4.5) + rexml crass (1.0.6) + database_cleaner (2.0.1) + database_cleaner-active_record (~> 2.0.0) + database_cleaner-active_record (2.0.1) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) diff-lcs (1.4.4) docile (1.3.5) + dotenv (2.7.6) + dotenv-rails (2.7.6) + dotenv (= 2.7.6) + railties (>= 3.2) erubi (1.10.0) execjs (2.8.0) + factory_bot (4.11.1) + activesupport (>= 3.0.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) + railties (>= 3.0.0) faraday (1.4.1) faraday-excon (~> 1.1) faraday-net_http (~> 1.0) @@ -84,6 +104,11 @@ GEM faraday_middleware (1.0.0) faraday (~> 1.0) ffi (1.15.0) + ffi (1.15.0-java) + ffi (1.15.0-x64-mingw32) + ffi (1.15.0-x86-mingw32) + figaro (1.2.0) + thor (>= 0.14.0, < 2) gh (0.18.0) activesupport (~> 5.0) addressable (~> 2.4) @@ -94,15 +119,21 @@ GEM net-http-pipeline globalid (0.4.2) activesupport (>= 4.2.0) + hashdiff (1.0.1) highline (2.0.3) i18n (1.8.10) concurrent-ruby (~> 1.0) jbuilder (2.11.2) activesupport (>= 5.0.0) json (2.5.1) + json (2.5.1-java) json_pure (2.5.1) + jwt (2.2.3) launchy (2.4.3) addressable (~> 2.3) + launchy (2.4.3-java) + addressable (~> 2.3) + spoon (~> 0.0.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -118,27 +149,43 @@ GEM mini_portile2 (2.5.1) minitest (5.14.4) msgpack (1.4.2) + msgpack (1.4.2-java) multi_json (1.15.0) multipart-post (2.1.1) net-http-persistent (2.9.4) net-http-pipeline (1.0.1) nio4r (2.5.7) + nio4r (2.5.7-java) nokogiri (1.11.3) mini_portile2 (~> 2.5.0) racc (~> 1.4) + nokogiri (1.11.3-java) + racc (~> 1.4) + nokogiri (1.11.3-x64-mingw32) + racc (~> 1.4) + nokogiri (1.11.3-x86-mingw32) + racc (~> 1.4) parallel (1.20.1) parser (3.0.1.1) ast (~> 2.4.1) pg (1.2.3) + pg (1.2.3-x64-mingw32) + pg (1.2.3-x86-mingw32) pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) + pry (0.14.1-java) + coderay (~> 1.1) + method_source (~> 1.0) + spoon (~> 0.0) public_suffix (4.0.6) puma (3.12.6) + puma (3.12.6-java) pusher-client (0.6.2) json websocket (~> 1.0) racc (1.5.2) + racc (1.5.2-java) rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -219,12 +266,16 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + shoulda-matchers (4.5.1) + activesupport (>= 4.2.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.3) + spoon (0.0.6) + ffi sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -234,6 +285,7 @@ GEM sprockets (>= 3.0.0) thor (1.1.0) thread_safe (0.3.6) + thread_safe (0.3.6-java) tilt (2.0.10) travis (1.10.0) faraday (~> 1.0) @@ -245,29 +297,49 @@ GEM pusher-client (~> 0.4) tzinfo (1.2.9) thread_safe (~> 0.1) + tzinfo-data (1.2021.1) + tzinfo (>= 1.0.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (2.0.0) + vcr (6.0.0) web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) + webmock (3.13.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) websocket (1.2.9) websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) + websocket-driver (0.7.3-java) + websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) PLATFORMS + java ruby + x64-mingw32 + x86-mingw32 + x86-mswin32 DEPENDENCIES + bcrypt (~> 3.1.7) bootsnap + byebug capybara coffee-rails (~> 4.2) + database_cleaner + dotenv-rails + factory_bot_rails + figaro jbuilder (~> 2.5) + jwt launchy listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) @@ -277,11 +349,14 @@ DEPENDENCIES rspec-rails rubocop-rails sass-rails (~> 5.0) + shoulda-matchers simplecov travis tzinfo-data uglifier (>= 1.3.0) + vcr web-console (>= 3.3.0) + webmock RUBY VERSION ruby 2.7.2p137 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e9d..b75105c163 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,10 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + helper_method :current_user + + def current_user + @current_user ||= User.find(cookies.encrypted[:user_id]) if cookies[:user_id] + end + end diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb new file mode 100644 index 0000000000..bffb498b61 --- /dev/null +++ b/app/controllers/discover_controller.rb @@ -0,0 +1,7 @@ +class DiscoverController < ApplicationController + + def index + @top_movies = ImdbService.top_movies + end + +end \ No newline at end of file diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..fa7bc151ae --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,10 @@ +class MoviesController < ApplicationController + + def index + @movie_search = ImdbService.top_movies_search(params[:movie_title]) + end + + def show + @title = params[:title] + end +end \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..d339c603d8 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,24 @@ +class SessionsController < ApplicationController + + def new + + end + + def create + found_user = User.find_by(email: params[:email]) + if found_user && found_user.authenticate(params[:password]) + cookies.encrypted[:user_id] = found_user.id + flash[:success] = "Welcome, #{found_user.email}!" + redirect_to "/dashboard" + else + flash[:error] = "Your username or password are incorrect" + redirect_to "/login" + end + end + + def destroy + cookies.delete :user_id + redirect_to '/' + end + +end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..aa68a1d30f --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,39 @@ +class UsersController < ApplicationController + + def new + @user = User.new + end + + def create + user = user_params + user[:email] = user[:email].downcase + new_user = User.new(user) + + if new_user.save + # session[:user_id] = new_user.id + cookies.encrypted[:user_id] = new_user.id + flash[:success] = "Account created succesfully!" + # flash[:success] = "Welcome, #{new_user.email}!" + redirect_to "/dashboard" + + else + if User.find_by(email: user[:email]) != nil + flash[:error] = "invalid email or password" + else + flash[:error] = new_user.errors.full_messages + end + redirect_to '/register' + end + end + + def show + + end + + private + + def user_params + params.require(:user).permit(:email, :password, :password_confirmation) + end + +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..393d157768 --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,6 @@ +class WelcomeController < ApplicationController + + def index + end + +end \ No newline at end of file diff --git a/app/models/attendee.rb b/app/models/attendee.rb new file mode 100644 index 0000000000..0cb7af8f59 --- /dev/null +++ b/app/models/attendee.rb @@ -0,0 +1,9 @@ +class Attendee < ApplicationRecord + + belongs_to :user + belongs_to :movie_party + + validates_presence_of :user, :movie_party + validates_uniqueness_of :user, scope: :movie_party #, allow_nil: true + +end diff --git a/app/models/friend.rb b/app/models/friend.rb new file mode 100644 index 0000000000..a80be01d1a --- /dev/null +++ b/app/models/friend.rb @@ -0,0 +1,10 @@ +class Friend < ApplicationRecord + + belongs_to :friender, class_name: 'User' + belongs_to :friendee, class_name: 'User' + + validates_presence_of :friender, :friendee + + # validates :friender, uniqueness: { scope: :friendee } + +end diff --git a/app/models/movie_party.rb b/app/models/movie_party.rb new file mode 100644 index 0000000000..05f978e381 --- /dev/null +++ b/app/models/movie_party.rb @@ -0,0 +1,10 @@ +class MovieParty < ApplicationRecord + + + has_many :attendees, dependent: :destroy + has_many :users, through: :attendees + + belongs_to :user + + validates_presence_of :user_id, :movie_title, :date_time +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..2a7de930f1 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,17 @@ +class User < ApplicationRecord + + has_secure_password + + has_many :friends, foreign_key: :friendee_id, dependent: :destroy + has_many :friendees, through: :friends + has_many :friend_alias, class_name: 'Friend', foreign_key: :friender_id, dependent: :destroy + has_many :frienders, through: :friend_alias + + has_many :attendees, dependent: :destroy + has_many :movie_parties, through: :attendees + has_many :movie_parties, dependent: :destroy + + validates :email, uniqueness: true, presence: true + validates_presence_of :password_digest, require: true + +end diff --git a/app/services/imdb_service.rb b/app/services/imdb_service.rb new file mode 100644 index 0000000000..63a2898d69 --- /dev/null +++ b/app/services/imdb_service.rb @@ -0,0 +1,30 @@ +class ImdbService + def self.top_movies_search(search)\ + imbd_api = ENV['IMDB_KEY'] + search_terms = search.gsub(' ', '+') + response_1 = Faraday.get "https://api.themoviedb.org/3/search/movie?api_key=#{imbd_api}&query=#{search_terms}&page=1" + response_2 = Faraday.get "https://api.themoviedb.org/3/search/movie?api_key=#{imbd_api}&query=#{search_terms}&page=2" + body_1 = response_1.body + body_2 = response_2.body + ruby_body_1 = JSON.parse(body_1, symbolize_names: true) + ruby_body_2 = JSON.parse(body_2, symbolize_names: true) + ruby_body = ruby_body_1[:results].concat(ruby_body_2[:results]) + return 'No Movies Found' if ruby_body == [] + ruby_body.each_with_object([]) do |movie, array| + array.push({title: movie[:title], vote: movie[:vote_average]}) + end + end + def self.top_movies + imbd_api = ENV['IMDB_KEY'] + response_1 = Faraday.get "https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=#{imbd_api}&page=1" + response_2 = Faraday.get "https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=#{imbd_api}&page=2" + body_1 = response_1.body + body_2 = response_2.body + ruby_body_1 = JSON.parse(body_1, symbolize_names: true) + ruby_body_2 = JSON.parse(body_2, symbolize_names: true) + ruby_body = ruby_body_1[:results].concat(ruby_body_2[:results]) + ruby_body.each_with_object([]) do |movie, array| + array.push({title: movie[:title], vote: movie[:vote_average]}) + end + end +end diff --git a/app/views/discover/index.html.erb b/app/views/discover/index.html.erb new file mode 100644 index 0000000000..1d0feca1fc --- /dev/null +++ b/app/views/discover/index.html.erb @@ -0,0 +1,16 @@ +

Top 40 Movies

+ +<%= form_with url: '/movies', method: :get, local: true do |form| %> + <%= form.label :movie_title, "Search by Title:" %> + <%= form.text_field :movie_title %> + <%= form.submit "Find Top Rated Movies" %> +<% end %> + +
    + <% @top_movies.each do |movie| %> +
  1. <%= link_to "#{movie[:title]}", "/movies/details?title=#{movie[:title]}" %> +
  2. + <% end %> +
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 81192299ad..b3317d98f9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,9 @@
+ <% flash.each do |name, msg| %> + <%= content_tag :div, msg, class: name %> + <% end %> <%= yield %>