diff --git a/Gemfile b/Gemfile index c004f4ca..c48b9d73 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,8 @@ gem "sinatra-activerecord" gem "sqlite3" gem "pry" gem "require_all" + + +gem "artii", "~> 2.1" +gem "tty-prompt", "~> 0.21.0" +gem "colorize" diff --git a/Gemfile.lock b/Gemfile.lock index 9589226d..8265ccf3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,56 +1,77 @@ GEM remote: https://rubygems.org/ specs: - activemodel (6.0.3.1) - activesupport (= 6.0.3.1) - activerecord (6.0.3.1) - activemodel (= 6.0.3.1) - activesupport (= 6.0.3.1) - activesupport (6.0.3.1) + activemodel (6.1.3) + activesupport (= 6.1.3) + activerecord (6.1.3) + activemodel (= 6.1.3) + activesupport (= 6.1.3) + activesupport (6.1.3) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - coderay (1.1.1) - concurrent-ruby (1.1.6) - i18n (1.8.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + artii (2.1.2) + coderay (1.1.3) + colorize (0.8.1) + concurrent-ruby (1.1.8) + equatable (0.6.1) + i18n (1.8.9) concurrent-ruby (~> 1.0) - method_source (0.8.2) - minitest (5.14.1) - mustermann (1.0.3) - pry (0.10.4) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) + method_source (1.0.0) + minitest (5.14.4) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + necromancer (0.5.1) + pastel (0.7.4) + equatable (~> 0.6) + tty-color (~> 0.5) + pry (0.14.0) + coderay (~> 1.1) + method_source (~> 1.0) rack (2.2.3) - rack-protection (2.0.7) + rack-protection (2.1.0) rack - require_all (1.3.3) - sinatra (2.0.7) + require_all (3.0.0) + ruby2_keywords (0.0.4) + sinatra (2.1.0) mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.7) + rack (~> 2.2) + rack-protection (= 2.1.0) tilt (~> 2.0) - sinatra-activerecord (2.0.12) - activerecord (>= 3.2) + sinatra-activerecord (2.0.22) + activerecord (>= 4.1) sinatra (>= 1.0) - slop (3.6.0) - sqlite3 (1.3.13) - thread_safe (0.3.6) + sqlite3 (1.4.2) tilt (2.0.10) - tzinfo (1.2.7) - thread_safe (~> 0.1) - zeitwerk (2.3.0) + tty-color (0.6.0) + tty-cursor (0.7.1) + tty-prompt (0.21.0) + necromancer (~> 0.5.0) + pastel (~> 0.7.0) + tty-reader (~> 0.7.0) + tty-reader (0.7.0) + tty-cursor (~> 0.7) + tty-screen (~> 0.7) + wisper (~> 2.0.0) + tty-screen (0.8.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + wisper (2.0.1) + zeitwerk (2.4.2) PLATFORMS - ruby + x86_64-linux DEPENDENCIES + artii (~> 2.1) + colorize pry require_all sinatra-activerecord sqlite3 + tty-prompt (~> 0.21.0) BUNDLED WITH - 1.14.6 + 2.2.11 diff --git a/apps/models/genre.rb b/apps/models/genre.rb new file mode 100644 index 00000000..07555b54 --- /dev/null +++ b/apps/models/genre.rb @@ -0,0 +1,8 @@ +class Genre < ActiveRecord::Base + has_many :movies + + # def self.genres + # #return all genres + # end + +end \ No newline at end of file diff --git a/apps/models/guest.rb b/apps/models/guest.rb new file mode 100644 index 00000000..a27411cf --- /dev/null +++ b/apps/models/guest.rb @@ -0,0 +1,8 @@ +class Guest < ActiveRecord::Base + has_many :tickets + + # def self.guestbook + # #return all guests + # end + +end \ No newline at end of file diff --git a/apps/models/movie.rb b/apps/models/movie.rb new file mode 100644 index 00000000..fb4a24df --- /dev/null +++ b/apps/models/movie.rb @@ -0,0 +1,41 @@ +class Movie < ActiveRecord::Base + belongs_to :theater + belongs_to :genre + + # @@all = [] + + # def initialize + # @@all< return array + # #use that array find each movie title + # #return each movie title in array + + + # end + + + +end diff --git a/apps/models/theater.rb b/apps/models/theater.rb new file mode 100644 index 00000000..c170bedb --- /dev/null +++ b/apps/models/theater.rb @@ -0,0 +1,10 @@ +class Theater < ActiveRecord::Base + has_many :tickets + has_many :guests, through: :tickets + has_many :movies + + # def self.theaters + # #return theaters + # #MAYBE RETURN THEATERS AND THEIR MOVIES + # end +end diff --git a/apps/models/ticket.rb b/apps/models/ticket.rb new file mode 100644 index 00000000..d4b839c7 --- /dev/null +++ b/apps/models/ticket.rb @@ -0,0 +1,10 @@ +class Ticket < ActiveRecord::Base + belongs_to :guest + belongs_to :theater + belongs_to :movie + + # def self.purchases + # #return all purchases + # end + +end diff --git a/bin/program.rb b/bin/program.rb new file mode 100644 index 00000000..6c728dc0 --- /dev/null +++ b/bin/program.rb @@ -0,0 +1,92 @@ +require 'pry' +require_relative '../config/environment' + +def welcome +title=Artii::Base.new(:font=> "cursive") +puts "Welcome to" +puts title.asciify("Command Theater") +end + + +def signup + prompt = TTY::Prompt.new + login_choice = prompt.select("New users please Sign Up",["Sign Up", "Exit"]) + if (login_choice == "Sign Up") + new_username = prompt.ask("What is your username?") + new_password = prompt.ask("What is your password?") + $g = Guest.create(name: "#{new_username}", password: "#{new_password}") + + puts "Lets start watching!" + else + puts "Incorrect username or password" + exit! + end + end + + + + +def search + movies = Movie.all.map {|movie| movie.title} + genres = Genre.all.map {|genre| genre.genre} + prompt = TTY::Prompt.new + search_choice = prompt.select("What would you like to see?", ["All Movies", "Genres"]) + if (search_choice == "All Movies") + prompt = TTY::Prompt.new + choice = prompt.select("Pick a movie", movies) + puts "You selected #{choice}!!! We love that one!" + select_movie = Movie.find_by(title: choice) + + menu_options = prompt.select("What would you like to do next", ["Purchase Ticket", "Start Over"]) + if menu_options == "Purchase Ticket" + puts "Here is your ticket! Excited yet?!" + your_ticket = Ticket.create(theater_id: Theater.all.first.id, movie_id: select_movie.id, guest_id: $g.id) + puts your_ticket + puts "Please save this id for your confirmation number." + puts "You're going to see the #{select_movie.genre.genre} movie, #{your_ticket.movie.title}, @ #{select_movie.showtime} " + end + + elsif (search_choice == "Genres") + prompt = TTY::Prompt.new + genre_choice = prompt.select("Pick a genre", genres) + puts "You selected #{genre_choice}. That's a popular one!" + select_genre = Genre.find_by(genre: genre_choice) + genre_titles = select_genre.movies.map {|movie| movie.title} + prompt = TTY::Prompt.new + genre_movie_choice = prompt.select("Which movie?", genre_titles) + ticket_choice = Movie.find_by(title: genre_movie_choice) + + + prompt = TTY::Prompt.new + menu_options = prompt.select("What would you like to do next", ["Purchase Ticket", "Start Over"]) + if menu_options == "Purchase Ticket" + puts "Here is your ticket! Excited yet?!" + your_ticket = Ticket.create(theater_id: Theater.all.first.id, movie_id: ticket_choice.id, guest_id: $g.id) + puts your_ticket + puts "Please save this id for your confirmation number." + puts "You're going to see a #{ticket_choice.genre.genre} movie, #{your_ticket.movie.title}, @ #{ticket_choice.showtime} " + + else + welcome + end + end +end + + + + + +####how to save rat + def thanks + puts "Thank you for your purchase! Commando Theater is b.y.o.b so feel free and WELCOME to bring your own refreshments. We cant wait to watch a movie with you!" + prompt = TTY::Prompt.new + thanks_choice = prompt.ask("Please leave us a rating from 1-5") + puts "Thank you for your feedback!" + end + + + +welcome +signup +search +thanks diff --git a/bin/run.rb b/bin/run.rb deleted file mode 100644 index cf08c338..00000000 --- a/bin/run.rb +++ /dev/null @@ -1,5 +0,0 @@ -require_relative '../config/environment' - - - -puts "HELLO WORLD" diff --git a/config/database.yml b/config/database.yml index 31199e77..6390bff1 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,5 @@ development: adapter: sqlite3 - database: db/development.db + database: db/development.db pool: 5 timeout: 5000 diff --git a/config/environment.rb b/config/environment.rb index 4dbe13e5..feba57b2 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,7 @@ require 'bundler' Bundler.require + ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.db') -require_all 'lib' +ActiveRecord::Base.logger = nil +require_all 'apps' diff --git a/db/migrate/20210309224256_create_movies_table.rb b/db/migrate/20210309224256_create_movies_table.rb new file mode 100644 index 00000000..b9e6ab52 --- /dev/null +++ b/db/migrate/20210309224256_create_movies_table.rb @@ -0,0 +1,10 @@ +class CreateMoviesTable < ActiveRecord::Migration[6.1] + def change + create_table :movies do |t| + t.string :title_id + t.string :genre_id + t.integer :showtime_id + t.string :theater + end + end +end diff --git a/db/migrate/20210309224721_create_theaters_table.rb b/db/migrate/20210309224721_create_theaters_table.rb new file mode 100644 index 00000000..f642a71b --- /dev/null +++ b/db/migrate/20210309224721_create_theaters_table.rb @@ -0,0 +1,7 @@ +class CreateTheatersTable < ActiveRecord::Migration[6.1] + def change + create_table :theaters do |t| + t.string :name + end + end +end diff --git a/db/migrate/20210309224824_create_genres_table.rb b/db/migrate/20210309224824_create_genres_table.rb new file mode 100644 index 00000000..b81537f1 --- /dev/null +++ b/db/migrate/20210309224824_create_genres_table.rb @@ -0,0 +1,7 @@ +class CreateGenresTable < ActiveRecord::Migration[6.1] + def change + create_table :genres do |t| + t.string :genre + end + end +end diff --git a/db/migrate/20210309224916_create_guests_table.rb b/db/migrate/20210309224916_create_guests_table.rb new file mode 100644 index 00000000..244c3e53 --- /dev/null +++ b/db/migrate/20210309224916_create_guests_table.rb @@ -0,0 +1,7 @@ +class CreateGuestsTable < ActiveRecord::Migration[6.1] + def change + create_table :guests do |t| + t.string :name + end + end +end diff --git a/db/migrate/20210309225013_create_tickets_table.rb b/db/migrate/20210309225013_create_tickets_table.rb new file mode 100644 index 00000000..c4ca2ddc --- /dev/null +++ b/db/migrate/20210309225013_create_tickets_table.rb @@ -0,0 +1,9 @@ +class CreateTicketsTable < ActiveRecord::Migration[6.1] + def change + create_table :tickets do |t| + t.string :theater + t.string :movie + t.string :guest + end + end +end diff --git a/db/migrate/20210310162854_change_movie_table_column_to_accept_ids.rb b/db/migrate/20210310162854_change_movie_table_column_to_accept_ids.rb new file mode 100644 index 00000000..82b871eb --- /dev/null +++ b/db/migrate/20210310162854_change_movie_table_column_to_accept_ids.rb @@ -0,0 +1,6 @@ +class ChangeMovieTableColumnToAcceptIds < ActiveRecord::Migration[6.1] + def change + rename_column(:movies, :genre, :genre_id) + change_column(:movies, :genre_id, :integer) + end +end diff --git a/db/migrate/20210310163524_changing_table_columns_to_accept_ids.rb b/db/migrate/20210310163524_changing_table_columns_to_accept_ids.rb new file mode 100644 index 00000000..78da5309 --- /dev/null +++ b/db/migrate/20210310163524_changing_table_columns_to_accept_ids.rb @@ -0,0 +1,13 @@ +class ChangingTableColumnsToAcceptIds < ActiveRecord::Migration[6.1] + def change + rename_column(:movies, :theater, :theater_id) + change_column(:movies, :theater_id, :integer) + rename_column(:tickets, :theater, :theater_id) + rename_column(:tickets, :movie, :movie_id) + rename_column(:tickets, :guest, :guest_id) + change_column(:tickets, :theater_id, :integer) + change_column(:tickets, :movie_id, :integer) + change_column(:tickets, :guest_id, :integer) + + end +end diff --git a/db/migrate/20210310214457_hadichloun.rb b/db/migrate/20210310214457_hadichloun.rb new file mode 100644 index 00000000..58e07316 --- /dev/null +++ b/db/migrate/20210310214457_hadichloun.rb @@ -0,0 +1,5 @@ +class Hadichloun < ActiveRecord::Migration[6.1] + def change + add_column(:guests, :password, :integer) + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..82ec8d28 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,41 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2021_03_10_214457) do + + create_table "genres", force: :cascade do |t| + t.string "genre" + end + + create_table "guests", force: :cascade do |t| + t.string "name" + t.integer "password" + end + + create_table "movies", force: :cascade do |t| + t.string "title" + t.integer "genre_id" + t.integer "showtime" + t.integer "theater_id" + end + + create_table "theaters", force: :cascade do |t| + t.string "name" + end + + create_table "tickets", force: :cascade do |t| + t.integer "theater_id" + t.integer "movie_id" + t.integer "guest_id" + end + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 00000000..b9708aa0 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,59 @@ +Theater.destroy_all +Guest.destroy_all +Genre.destroy_all +Movie.destroy_all +Ticket.destroy_all + + + +commando=Theater.create(name: "Commando Theater") + +rom_com=Genre.create(genre: "Romantic Comedy") +action=Genre.create(genre: "Action") +sci_fi=Genre.create(genre: "Science Fiction") +slasher=Genre.create(genre: "Slasher") + +donovan = Guest.create(name: "theater", password: "123") +g1=Guest.create(name: "Hadi", password: "123") +g2=Guest.create(name: "Donovan", password: "123") +g3=Guest.create(name: "Drake", password: "123") +g4=Guest.create(name: "Sonny", password: "123") +g5=Guest.create(name: "Shrek", password: "123") +g6=Guest.create(name: "Neo", password: "123") +g7=Guest.create(name: "Trinity", password: "123") +g8=Guest.create(name: "P.Rudd", password: "123") +g9=Guest.create(name: "Jackie Chan", password: "123") +g10=Guest.create(name: "Bagheera", password: "123") + +m1 = Movie.create(title: "Groundhog Day", genre_id: rom_com.id, showtime: 6, theater_id: commando.id ) +m2 = Movie.create(title: "Clueless", genre_id: rom_com.id, showtime: 3, theater_id: commando.id) +m3 = Movie.create(title: "Sleepless in Seattle", genre_id: rom_com.id, showtime: 11, theater_id: commando.id) +m4 = Movie.create(title: "Rush Hour", genre_id: action.id, showtime: 4, theater_id: commando.id) +m5 = Movie.create(title: "The Matrix", genre_id: action.id, showtime: 12, theater_id: commando.id) +m6 = Movie.create(title: "Inside Man", genre_id: action.id, showtime: 6, theater_id: commando.id ) +m7 = Movie.create(title: "Mars Attacks", genre_id: sci_fi.id, showtime: 9, theater_id:commando.id ) +m8 = Movie.create(title: "Predator", genre_id: sci_fi.id, showtime: 12, theater_id: commando.id ) +m9 = Movie.create(title: "Jurassic Park", genre_id: sci_fi.id, showtime: 4, theater_id: commando.id ) +m10 = Movie.create(title: "I Know What You Did Last Summer", genre_id: slasher.id, showtime: 11, theater_id: commando.id ) +m11 = Movie.create(title: "Scream", genre_id: slasher.id, showtime: 12, theater_id: commando.id ) +m12 = Movie.create(title: "Halloween", genre_id: slasher.id, showtime: 10, theater_id:commando.id ) + + +t1=Ticket.create(theater_id: commando.id, movie_id: m1.id, guest_id: g1.id) +t2=Ticket.create(theater_id: commando.id, movie_id: m2.id, guest_id: g2.id) +t3=Ticket.create(theater_id: commando.id, movie_id: m3.id, guest_id: g3.id) +t4=Ticket.create(theater_id: commando.id, movie_id: m4.id, guest_id: g4.id) +t5=Ticket.create(theater_id: commando.id, movie_id: m5.id, guest_id: g5.id) +t6=Ticket.create(theater_id: commando.id, movie_id: m6.id, guest_id: g6.id) +t7=Ticket.create(theater_id: commando.id, movie_id: m7.id, guest_id: g7.id) +t8=Ticket.create(theater_id: commando.id, movie_id: m8.id, guest_id: g8.id) +t9=Ticket.create(theater_id: commando.id, movie_id: m9.id, guest_id: g9.id) +t10=Ticket.create(theater_id: commando.id, movie_id: m10.id, guest_id: g10.id) +t11=Ticket.create(theater_id: commando.id, movie_id: m11.id, guest_id: g1.id) +t12=Ticket.create(theater_id: commando.id, movie_id: m12.id, guest_id: g1.id) +t13=Ticket.create(theater_id: commando.id, movie_id: m2.id, guest_id: g2.id) +t14=Ticket.create(theater_id: commando.id, movie_id: m2.id, guest_id: g2.id) +t15=Ticket.create(theater_id: commando.id, movie_id: m3.id, guest_id: g4.id) +t16=Ticket.create(theater_id: commando.id, movie_id: m9.id, guest_id: g5.id) +t17=Ticket.create(theater_id: commando.id, movie_id: m11.id, guest_id: g5.id) +