diff --git a/Gemfile b/Gemfile index fecd89c7..3c07e3a5 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby - +gem 'awesome_print' # Use jquery as the JavaScript library gem 'jquery-rails' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder @@ -22,7 +22,7 @@ gem 'jbuilder', '~> 2.0' gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' +gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server # gem 'unicorn' @@ -42,4 +42,3 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end - diff --git a/Gemfile.lock b/Gemfile.lock index c701ada1..1859852b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,115 +1,125 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.0.1) - actionpack (= 5.0.0.1) - nio4r (~> 1.2) + actioncable (5.0.6) + actionpack (= 5.0.6) + nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) + actionmailer (5.0.6) + actionpack (= 5.0.6) + actionview (= 5.0.6) + activejob (= 5.0.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.0.1) - actionview (= 5.0.0.1) - activesupport (= 5.0.0.1) + actionpack (5.0.6) + actionview (= 5.0.6) + activesupport (= 5.0.6) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.0.1) - activesupport (= 5.0.0.1) + actionview (5.0.6) + activesupport (= 5.0.6) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.0.1) - activesupport (= 5.0.0.1) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.6) + activesupport (= 5.0.6) globalid (>= 0.3.6) - activemodel (5.0.0.1) - activesupport (= 5.0.0.1) - activerecord (5.0.0.1) - activemodel (= 5.0.0.1) - activesupport (= 5.0.0.1) + activemodel (5.0.6) + activesupport (= 5.0.6) + activerecord (5.0.6) + activemodel (= 5.0.6) + activesupport (= 5.0.6) arel (~> 7.0) - activesupport (5.0.0.1) + activesupport (5.0.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) - binding_of_caller (0.7.2) + awesome_print (1.8.0) + bcrypt (3.1.11) + binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - builder (3.2.2) - byebug (9.0.6) + builder (3.2.3) + byebug (9.1.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) - concurrent-ruby (1.0.2) - debug_inspector (0.0.2) + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crass (1.0.3) + debug_inspector (0.0.3) erubis (2.7.0) execjs (2.7.0) - globalid (0.3.7) - activesupport (>= 4.1.0) - i18n (0.7.0) - jbuilder (2.6.0) - activesupport (>= 3.0.0, < 5.1) - multi_json (~> 1.2) - jquery-rails (4.2.1) + ffi (1.9.18) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (0.9.3) + concurrent-ruby (~> 1.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.3) - loofah (2.0.3) + json (1.8.6) + loofah (2.1.1) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.9.1) - multi_json (1.12.1) - nio4r (1.2.1) - nokogiri (1.6.8.1) - mini_portile2 (~> 2.1.0) - rack (2.0.1) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.1) + multi_json (1.13.1) + nio4r (2.2.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + rack (2.0.3) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.0.1) - actioncable (= 5.0.0.1) - actionmailer (= 5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) - activemodel (= 5.0.0.1) - activerecord (= 5.0.0.1) - activesupport (= 5.0.0.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0.1) + rails (5.0.6) + actioncable (= 5.0.6) + actionmailer (= 5.0.6) + actionpack (= 5.0.6) + actionview (= 5.0.6) + activejob (= 5.0.6) + activemodel (= 5.0.6) + activerecord (= 5.0.6) + activesupport (= 5.0.6) + bundler (>= 1.3.0) + railties (= 5.0.6) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.1) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (5.0.0.1) - actionpack (= 5.0.0.1) - activesupport (= 5.0.0.1) + railties (5.0.6) + actionpack (= 5.0.6) + activesupport (= 5.0.6) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.3.0) - rdoc (4.2.2) - json (~> 1.4) - sass (3.4.22) - sass-rails (5.0.6) + rake (12.3.0) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rdoc (4.3.0) + sass (3.5.5) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) @@ -118,41 +128,43 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - spring (2.0.0) + spring (2.0.2) activesupport (>= 4.2) - sprockets (3.7.0) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.12) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) - tzinfo (1.2.2) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + tzinfo (1.2.4) thread_safe (~> 0.1) - uglifier (3.0.3) + uglifier (4.1.4) execjs (>= 0.3.0, < 3) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) - websocket-driver (0.6.4) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.3) PLATFORMS ruby DEPENDENCIES + awesome_print + bcrypt (~> 3.1.7) byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails - rails (~> 5.0) + rails (~> 5.0.1) sass-rails (~> 5.0) sdoc (~> 0.4.0) spring @@ -161,4 +173,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.11.2 + 1.16.0 diff --git a/app/assets/javascripts/bookings.coffee b/app/assets/javascripts/bookings.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/bookings.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/restaurants.coffee b/app/assets/javascripts/restaurants.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/restaurants.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/users.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/bookings.scss b/app/assets/stylesheets/bookings.scss new file mode 100644 index 00000000..c9c87490 --- /dev/null +++ b/app/assets/stylesheets/bookings.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the bookings controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/restaurants.scss b/app/assets/stylesheets/restaurants.scss new file mode 100644 index 00000000..90372d50 --- /dev/null +++ b/app/assets/stylesheets/restaurants.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the restaurants controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 00000000..ccb1ed25 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 00000000..31a2eacb --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1..9a49a313 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,12 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + private + + def current_user + @current_user ||= User.find(session[:user_id]) if session[:user_id] + end + + helper_method :current_user end diff --git a/app/controllers/bookings_controller.rb b/app/controllers/bookings_controller.rb new file mode 100644 index 00000000..df7b11b3 --- /dev/null +++ b/app/controllers/bookings_controller.rb @@ -0,0 +1,16 @@ +class BookingsController < ApplicationController + + def create + @restaurant = Restaurant.find(params[:restaurant_id]) + @booking = @restaurant.bookings.new + @booking.time = params[:booking][:time] + params[:hour].hour + @booking.n_people = params[:booking][:time] + @booking.user = current_user + + if @booking.save + flash[:notice] = "Reservation made at #{@restaurant.name} on #{@booking.time.month}/#{@booking.time.day} at #{@booking.time.hour}" + redirect_to root_path + end + end + +end diff --git a/app/controllers/restaurants_controller.rb b/app/controllers/restaurants_controller.rb new file mode 100644 index 00000000..f26b73ab --- /dev/null +++ b/app/controllers/restaurants_controller.rb @@ -0,0 +1,42 @@ +class RestaurantsController < ApplicationController + + def index + @restaurants = Restaurant.all + end + + def show + @restaurant = Restaurant.find(params[:id]) + @bookings = @restaurant.bookings + @booking = Booking.new + end + + def new + @restaurant = Restaurant.new + end + + def create + @restaurant = Restaurant.new + @restaurant.name = params[:restaurant][:name] + @restaurant.description = params[:restaurant][:description] + @restaurant.open_time = params[:restaurant][:open_time] + @restaurant.close_time = params[:restaurant][:close_time] + @restaurant.price = params[:restaurant][:price] + + if @restaurant.save + redirect_to restaurants_url + end + end + + def edit + + end + + def update + + end + + def destroy + + end + +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 00000000..4e2a0e29 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,22 @@ +class SessionsController < ApplicationController + + def create + user = User.find_by(email: params[:email]) + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + flash[:notice] = ["Successfully logged in!"] + redirect_to restaurants_url + else + flash[:alert] = ["Username/password are incorrect, please try again!"] + render :new + end + end + + def destroy + session[:user_id] = nil + flash[:notice] = ["Successfully logged out!"] + redirect_to restaurants_url + end + + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 00000000..0a441132 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,26 @@ +class UsersController < ApplicationController + + def new + @user = User.new + end + + def create + @user = User.new + @user.email = params[:user][:email] + @user.password = params[:user][:password] + @user.password_confirmation = params[:user][:password_confirmation] + @user.kind = params[:user_kind] + + if @user.save + session[:user_id] = @user.id + if @user.kind == "owner" + redirect_to restaurant_form_url + else + redirect_to root_url + else + flash.now[:alert] = @user.errors.full_messages + render :new + end + end + +end diff --git a/app/helpers/bookings_helper.rb b/app/helpers/bookings_helper.rb new file mode 100644 index 00000000..c10c7c45 --- /dev/null +++ b/app/helpers/bookings_helper.rb @@ -0,0 +1,2 @@ +module BookingsHelper +end diff --git a/app/helpers/restaurants_helper.rb b/app/helpers/restaurants_helper.rb new file mode 100644 index 00000000..3937c4c7 --- /dev/null +++ b/app/helpers/restaurants_helper.rb @@ -0,0 +1,2 @@ +module RestaurantsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 00000000..309f8b2e --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 00000000..2310a240 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/booking.rb b/app/models/booking.rb new file mode 100644 index 00000000..812f0095 --- /dev/null +++ b/app/models/booking.rb @@ -0,0 +1,4 @@ +class Booking < ApplicationRecord + belongs_to :restaurant + belongs_to :user +end diff --git a/app/models/restaurant.rb b/app/models/restaurant.rb new file mode 100644 index 00000000..f48f907d --- /dev/null +++ b/app/models/restaurant.rb @@ -0,0 +1,4 @@ +class Restaurant < ApplicationRecord + belongs_to :user + has_many :bookings +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..3494a272 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,9 @@ +class User < ApplicationRecord + has_secure_password + + validates :email, presence: true + validates :email, uniqueness: { case_sensitive: false } + + has_one :restaurant + has_many :bookings +end diff --git a/app/views/bookings/_booking_form.html.erb b/app/views/bookings/_booking_form.html.erb new file mode 100644 index 00000000..9773d8b6 --- /dev/null +++ b/app/views/bookings/_booking_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for [restaurant, booking] do |f| %> +

+ <%= f.label :time, "Date" %> + <%= f.date_field :time %> +

+

+ <%= label_tag (:at) %> + <%= time_field_tag :hour %> +

+

+ <%= f.label :n_people, "How many people?" %> + <%= f.number_field :n_people %> +

+

+ <%= f.submit %> +

+<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c32feae9..e60fd8e7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,8 +7,36 @@ <%= csrf_meta_tags %> +<<<<<<< HEAD +
+ <% if flash[:notice] %> +
+======= +>>>>>>> master <%= yield %> + +<%= console %> diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb new file mode 100644 index 00000000..850cfa49 --- /dev/null +++ b/app/views/restaurants/index.html.erb @@ -0,0 +1,3 @@ +<% @restaurants.each do |restaurant| %> +

<%= link_to restaurant.name, restaurant_path(restaurant) %>

+<% end %> diff --git a/app/views/restaurants/new.html.erb b/app/views/restaurants/new.html.erb new file mode 100644 index 00000000..337c4f08 --- /dev/null +++ b/app/views/restaurants/new.html.erb @@ -0,0 +1,32 @@ +

Create Your Restaurant

+ +<%= form_for @restaurant do |f| %> + +

+ <%= f.label :name %> + <%= f.text_field :name %> +

+ +

+ <%= f.label :description %> + <%= f.text_area :description %> +

+ +

+ <%= f.label :open_time %> + <%= f.time_field :open_time %> +

+ +

+ <%= f.label :close_time %> + <%= f.time_field :close_time %> +

+ +

+ <%= f.label :price %> + <%= f.number_field :price %> +

+ + <%= f.submit 'Create' %> + +<% end %> diff --git a/app/views/restaurants/show.html.erb b/app/views/restaurants/show.html.erb new file mode 100644 index 00000000..49730d2e --- /dev/null +++ b/app/views/restaurants/show.html.erb @@ -0,0 +1,7 @@ +

<%= @restaurant.name %>

+

<%= @restaurant.description %>

+

Opens at: <%= @restaurant.open_time.localtime.hour %>

+

Closes at: <%= @restaurant.close_time.localtime.hour %>

+

Price: <%= @restaurant.price %>/5

+ +<%= render 'bookings/booking_form', restaurant: @restaurant, booking: @booking %> diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 00000000..2dc808aa --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,16 @@ +

Login, My Guy

+ +<%= form_tag sessions_path do %> + +

+ <%= label_tag :email %>
+ <%= text_field_tag :email, params[:email] %> +

+ +

+ <%= label_tag :password %>
+ <%= password_field_tag :password %> +

+ + <%= submit_tag "Log in" %> +<% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 00000000..364f1966 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,31 @@ +

Create a New User

+ +<%= form_for @user do |f| %> + +

+ <%= f.label :email %> + <%= f.email_field :email %> +

+ +

+ <%= f.label :password %> + <%= f.password_field :password %> +

+ +

+ <%= f.label :password_confirmation %> + <%= f.password_field :password_confirmation %> +

+ +

+ Are you a: + + + + + +

+ + <%= f.submit 'Sign Up' %> + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 787824f8..fa5855b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,11 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + root 'restaurants#index' + + resources :users + resources :sessions, only: [:new, :create, :destroy] + resources :restaurants do + resources :bookings + end + end diff --git a/db/migrate/20180123194645_create_users.rb b/db/migrate/20180123194645_create_users.rb new file mode 100644 index 00000000..e395bb32 --- /dev/null +++ b/db/migrate/20180123194645_create_users.rb @@ -0,0 +1,11 @@ +class CreateUsers < ActiveRecord::Migration[5.0] + def change + create_table :users do |t| + t.string :email + t.string :type + t.string :password_digest + + t.timestamps + end + end +end diff --git a/db/migrate/20180123194818_create_restaurants.rb b/db/migrate/20180123194818_create_restaurants.rb new file mode 100644 index 00000000..144d60c9 --- /dev/null +++ b/db/migrate/20180123194818_create_restaurants.rb @@ -0,0 +1,14 @@ +class CreateRestaurants < ActiveRecord::Migration[5.0] + def change + create_table :restaurants do |t| + t.string :name + t.text :description + t.datetime :open_time + t.datetime :close_time + t.integer :capacity + t.integer :price + t.integer :user_id + t.timestamps + end + end +end diff --git a/db/migrate/20180123195222_create_bookings.rb b/db/migrate/20180123195222_create_bookings.rb new file mode 100644 index 00000000..6b72420b --- /dev/null +++ b/db/migrate/20180123195222_create_bookings.rb @@ -0,0 +1,12 @@ +class CreateBookings < ActiveRecord::Migration[5.0] + def change + create_table :bookings do |t| + t.integer :user_id + t.integer :restaurant_id + t.datetime :time + t.integer :n_people + + t.timestamps + end + end +end diff --git a/db/migrate/20180123200055_change_times_to_time.rb b/db/migrate/20180123200055_change_times_to_time.rb new file mode 100644 index 00000000..fc51780b --- /dev/null +++ b/db/migrate/20180123200055_change_times_to_time.rb @@ -0,0 +1,6 @@ +class ChangeTimesToTime < ActiveRecord::Migration[5.0] + def change + change_column :restaurants, :open_time, :time + change_column :restaurants, :close_time, :time + end +end diff --git a/db/migrate/20180123210747_change_type_to_kind.rb b/db/migrate/20180123210747_change_type_to_kind.rb new file mode 100644 index 00000000..a23ed443 --- /dev/null +++ b/db/migrate/20180123210747_change_type_to_kind.rb @@ -0,0 +1,7 @@ +class ChangeTypeToKind < ActiveRecord::Migration[5.0] + def change + change_table :users do |t| + t.rename :type, :kind + end + end +end diff --git a/db/migrate/20180124143909_add_address_to_restaurants.rb b/db/migrate/20180124143909_add_address_to_restaurants.rb new file mode 100644 index 00000000..cbf6b952 --- /dev/null +++ b/db/migrate/20180124143909_add_address_to_restaurants.rb @@ -0,0 +1,7 @@ +class AddAddressToRestaurants < ActiveRecord::Migration[5.0] + def change + change_table :restaurants do |t| + t.string :address + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..b9a3eec6 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,45 @@ +# 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. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20180124143909) do + + create_table "bookings", force: :cascade do |t| + t.integer "user_id" + t.integer "restaurant_id" + t.datetime "time" + t.integer "n_people" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "restaurants", force: :cascade do |t| + t.string "name" + t.text "description" + t.time "open_time" + t.time "close_time" + t.integer "capacity" + t.integer "price" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "address" + end + + create_table "users", force: :cascade do |t| + t.string "email" + t.string "kind" + t.string "password_digest" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e85..f048f032 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,16 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +user1 = User.create(email: "jeff@rothwell.com", kind: "owner", password: "password") +user2 = User.create(email: "scott@huston.com", kind: "owner", password: "password") +user3 = User.create(email: "danny@chang.com", kind: "owner", password: "password") + +user1.create_restaurant(name: "Jeff's Burrito Joint", description: "Good burritos", + open_time: Time.new(2018, 1, 23, 13), close_time: Time.new(2018, 1, 23, 23), capacity: 20, + price: 3, address: "123 Some St. Toronto, ON") +user2.create_restaurant(name: "Scott's Rib House", description: "Cheap, mediocre ribs.", + open_time: Time.new(2018, 1, 23, 11), close_time: Time.new(2018, 1, 23, 22), capacity: 30, + price: 1, address: "245 Another Rd. Toronto, ON") +user3.create_restaurant(name: "Danny's Poutine and Fish-fry", description: "Fried fish and potatoes", + open_time: Time.new(2018, 1, 23, 7), close_time: Time.new(2018, 1, 23, 21), capacity: 200, + price: 4, address: "536 Random Ave. Toronto, ON") diff --git a/planning.md b/planning.md new file mode 100644 index 00000000..55b5687a --- /dev/null +++ b/planning.md @@ -0,0 +1,66 @@ +1. As a visitor, when I go to the homepage, I am presented with a list of restaurants. +1. As a visitor, when I click on a restaurant, I am presented with: + - address + - neighbourhood + - price range + - summary + - menu + - a list of available time slots +1. As a visitor, I do not have the option of making a reservation. +1. As a visitor, I want to sign up for a customer account so that I can make reservations online. +1. As a user I can login and logout. +1. As a customer, when I go to a restaurant's page, I can make a reservation for the time and party size of my choice. +1. As a customer I can go to a page to see a list of the reservations I’ve booked. +1. As a customer, if I try to make a reservation outside of a restaurant's opening hours, the reservation will not be made and I will be shown a message indicating why. +1. As a customer, if I try to make a reservation at a time when a restaurant is already at max capacity, the reservation will not be made and I will be shown a message indicating why. +1. As a customer, if I try to make a reservation for a date in the past, the reservation will not be made and I will be shown a message indicating why +1. As a customer, when I make a reservation at a restaurant, I want to receive loyalty points. +1. As a customer, when I go to my profile, I want to see my loyalty points. +1. As a customer, when I make a reservation, I want to be shown a confirmation message with the details of my reservation. +1. As a restaurant owner, when I go to my profile, I want to see a list of upcoming reservations for the next week. +1. As a restaurant owner, when I go to my profile, I want to see a list of customers who have made reservations at my restaurant in order of loyalty points. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the opening and closing times of my restaurant. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the maximum capacity of my restaurant. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the minimum and maximum party size that a reservation can be made for. + +Need to have: + +1. ~~As a visitor, when I go to the homepage, I am presented with a list of restaurants.~~ +1. ~~As a visitor, when I click on a restaurant, I am presented with: + - address + - neighbourhood + - price range + - summary + - menu + - a list of available time slots~~ +1. As a customer, when I go to a restaurant's page, I can make a reservation for the time and party size of my choice. +1. As a customer, if I try to make a reservation outside of a restaurant's opening hours, the reservation will not be made and I will be shown a message indicating why. +1. As a customer, if I try to make a reservation at a time when a restaurant is already at max capacity, the reservation will not be made and I will be shown a message indicating why. +1. As a customer, if I try to make a reservation for a date in the past, the reservation will not be made and I will be shown a message indicating why +1. On home page each restaurant has address, price range + + +Should have +1. As a visitor, I do not have the option of making a reservation. +1. ~~As a visitor, I want to sign up for a customer account so that I can make reservations online.~~ +1. ~~As a user I can login and logout.~~ +1. As a customer I can go to a page to see a list of the reservations I’ve booked. +1. As a customer, when I make a reservation, I want to be shown a confirmation message with the details of my reservation. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the opening and closing times of my restaurant. + +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the maximum capacity of my restaurant. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the minimum and maximum party size that a reservation can be made for. + + +Could have +1. As a customer, when I make a reservation at a restaurant, I want to receive loyalty points. +1. As a customer, when I go to my profile, I want to see my loyalty points. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the maximum capacity of my restaurant. +1. As a restaurant owner, when I go to my restaurant's edit page, I can set the minimum and maximum party size that a reservation can be made for. + +ASSUMPTIONS: +1. All restaurants have same schedule every day of the week +2. All bookings start on intervals of set_time (ie 20 minute meals, 60 minute meals, etc.) +3. Table sizes and arrangement are irrelevant - any number of people up to capacity can fit +1. All bookings last for 1 hour. +1. Can only book for current day. diff --git a/test/controllers/bookings_controller_test.rb b/test/controllers/bookings_controller_test.rb new file mode 100644 index 00000000..bfdeac67 --- /dev/null +++ b/test/controllers/bookings_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BookingsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/restaurants_controller_test.rb b/test/controllers/restaurants_controller_test.rb new file mode 100644 index 00000000..c0e4d28e --- /dev/null +++ b/test/controllers/restaurants_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RestaurantsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 00000000..6135ce6a --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SessionsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 00000000..6c3da770 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UsersControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/bookings.yml b/test/fixtures/bookings.yml new file mode 100644 index 00000000..56c142d2 --- /dev/null +++ b/test/fixtures/bookings.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user_id: 1 + restaurant_id: 1 + time: 2018-01-23 14:52:22 + n_people: 1 + +two: + user_id: 1 + restaurant_id: 1 + time: 2018-01-23 14:52:22 + n_people: 1 diff --git a/test/fixtures/restaurants.yml b/test/fixtures/restaurants.yml new file mode 100644 index 00000000..80aed36e --- /dev/null +++ b/test/fixtures/restaurants.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 00000000..59eeff57 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + email: MyString + type: + password_digest: MyString + +two: + email: MyString + type: + password_digest: MyString diff --git a/test/models/booking_test.rb b/test/models/booking_test.rb new file mode 100644 index 00000000..2f941b88 --- /dev/null +++ b/test/models/booking_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BookingTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/restaurant_test.rb b/test/models/restaurant_test.rb new file mode 100644 index 00000000..b45b7417 --- /dev/null +++ b/test/models/restaurant_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RestaurantTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 00000000..82f61e01 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end