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

Feat/new viewing party #28

Merged
merged 5 commits into from
Dec 2, 2023
Merged
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
58 changes: 58 additions & 0 deletions app/controllers/viewing_parties_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class ViewingPartiesController < ApplicationController
def new
@users = User.all
@user = User.find(params[:id])
@movie_runtime = params[:movie_runtime]
@movie_title = params[:movie_title]
@movie_id = params[:movie_id]
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]
}

@viewing_party = ViewingParty.create!(viewing_party_params)

#write the helper method
#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
@attendees.each do |id|
x = User.find_by(id: id)
@viewing_party.users << x
end

#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)

if @user_viewing_party
@user_viewing_party.update(host: true)
else
end
require 'pry'; binding.pry

if @viewing_party.save
#write a flash message here saying VP was created
redirect_to user_dashboard_path(@user.id)
else
render :new
end
end
end

# def add_selected_user_to_VP
# @users.each do |user|
# if params[:add_"#{@user.name}"] == "1"
# @viewing_party.users << user
# else
# end
# end
# end
4 changes: 1 addition & 3 deletions app/models/viewing_party.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class ViewingParty < ApplicationRecord
has_many :user_viewing_parties
has_many :users, through: :user_viewing_parties

validates :movie_id, :start_time, presence: true
validates :party_duration, :start_time, :movie_title, :movie_id, presence: true
end
2 changes: 1 addition & 1 deletion app/views/movies/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= render partial: "shared/nav" %>
<%= button_to "Discover", user_discover_path(@user.id), params: { value: "top-rated" }, method: :get, data: { turbo: false }, local: true %>
<%= button_to "Create a Viewing Party", "/users/#{@user.id}/movies/#{@movie.movie_id}/viewing-party/new", method: :get, data: { turbo: false }, local: true %>
<%= button_to "Create a Viewing Party", "/users/#{@user.id}/movies/#{@movie.movie_id}/viewing-party/new", params: { movie_id: @movie.movie_id, movie_title: @movie.title, movie_runtime: @movie.runtime }, method: :get, data: { turbo: false }, local: true %>

<p>Title: <%=@movie.title%></p>
<p>Vote Average: <%=@movie.vote_average%></p>
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@

<section id = "viewing-parties">
<h3>Parties I'm Hosting</h3>

<h3>Parties I'm Invited To</h3>

</section>
23 changes: 23 additions & 0 deletions app/views/viewing_parties/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h1><u>Create a Viewing Party</u></h1>

<h3><%= @movie_title %></h3>

<%= form_with(model: @viewing_party, url: viewing_party_form_path(@user.id, @movie_id) , method: :post) do |form| %>
<%= form.label :party_duration %>
<%= form.text_field :party_duration, value: @movie_runtime, min: @movie_runtime %>

<p><%= form.label :start_time %>
<%= form.time_field :start_time %></p>

<%@users.each do |user|%>
<% unless user.id == @user.id %>
<p><%= form.label "add_#{user.name}", class: "checkbox-label" %>
<%= form.check_box "user_ids", { multiple: true }, user.id, nil %></p>
<%end%>
<%end%>

<%= form.hidden_field :movie_title, value: @movie_title %>

<p><%= form.submit 'Create a Viewing Party' %></p>
<% end %>

2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eVaEMx/ltKwrJxLvnT9xkZVPtP73U+ky/P9q4JbrOoZS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Cime7DgYz9nnS9ERQ/APR8DoKFzqKmeHH5POAgEdc50GFWr+orBnI6zI6RjKvY8dcFakg+8k7acds6BRKPldH/ULHl+exE7WSIXni08qfkgcLWteDa8DCobJxUOrw8IicQgoKKM2bXG4aQvD88xolYQlDQuk2f3mCz5s38FMdSF0hoq6I2H//2Rc55g2MBMWHI4Sm/FlB0H+c3/syXi3XFeZx3LJoPIKo7yHJnD2Kwj5qN7grR2g55BzDOAUy0Z3ERczMscsaQvZhIS3clGxEpa8IQiCjLePcIFK2PrCvlVD4saiAcjPuxpZFHqQ1Lwws+p9+uMHgxKkJhsXKeZGBZf2pP1o5Ioy9gd9IQ3aLN+wcqBdCtK+Bn/U2FrBK5KF2gRz5BQczV0=--LfBW1+ECj5qxw478--LUf8KtcKsNK03EEsPFqe1A==
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
get '/users/:id/discover', to: 'users/discover#index', as: :user_discover
get '/users/:id/movies', to: 'movies#index', as: :top_rated_movies
get '/users/:id/movies/:movie_id', to: 'movies#show', as: :movie_show
get '/users/:id/movies/:movie_id/viewing-party/new', to: 'viewing_parties#new'
post '/users/:id/movies/:movie_id/viewing-party/new', to: 'viewing_parties#create', as: :viewing_party_form
end
2 changes: 2 additions & 0 deletions db/migrate/20231128002343_create_viewing_parties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
class CreateViewingParties < ActiveRecord::Migration[7.0]
def change
create_table :viewing_parties do |t|
t.string :party_duration
t.datetime :start_time
t.string :movie_title
t.string :movie_id

t.timestamps
Expand Down
46 changes: 24 additions & 22 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions spec/features/viewing_parties/new_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rails_helper'

RSpec.describe 'new viewing party page', type: :feature do
before(:each) do
@user_1 = User.create!(name: 'Joseph Lee', email: 'jlee230@turing.edu')
@user_2 = User.create!(name: 'Kam Kennedy', email: 'kkennedy230@turing.edu')
end
it 'has a form to create a new viewing party', :vcr do
visit user_discover_path(@user_1.id)
click_button 'Find Top Rated Movies'
click_on 'Pulp Fiction'
click_button 'Create a Viewing Party'

expect(page).to have_content('Pulp Fiction')
expect(page).to have_field('party_duration', type: 'text')
fill_in('party_duration', with: 170)

expect(page).to have_field('time', type: 'time')
fill_in('time', with: '20:00')
expect(page).to have_field('kam kennedy')
expect(page).to have_button('Create a Viewing Party')
click_on('Create a Viewing Party')
expect current_path.to eq(user_dashboard(@user_1.id))
end
end

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.hook_into :webmock
config.filter_sensitive_data('<TMDB>') { Rails.application.credentials.TMDB[:authorization] }
config.default_cassette_options = { re_record_interval: 7.days }
config.configure_rspec_metadata!
end
end