diff --git a/Gemfile b/Gemfile index fecd89c7..4407e7e7 100644 --- a/Gemfile +++ b/Gemfile @@ -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' @@ -33,13 +33,14 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'awesome_print' end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' + # 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..8f4faa5f 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.1 diff --git a/app/assets/javascripts/reservation.coffee b/app/assets/javascripts/reservation.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/reservation.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/restaurant.coffee b/app/assets/javascripts/restaurant.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/restaurant.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/user.coffee b/app/assets/javascripts/user.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/user.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/reservation.scss b/app/assets/stylesheets/reservation.scss new file mode 100644 index 00000000..05e7fc07 --- /dev/null +++ b/app/assets/stylesheets/reservation.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reservation 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/restaurant.scss b/app/assets/stylesheets/restaurant.scss new file mode 100644 index 00000000..294c9da4 --- /dev/null +++ b/app/assets/stylesheets/restaurant.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the restaurant 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..7bef9cf8 --- /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/user.scss b/app/assets/stylesheets/user.scss new file mode 100644 index 00000000..7c5eca9c --- /dev/null +++ b/app/assets/stylesheets/user.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the user 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..a7ea9400 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,27 @@ 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 + + def ensure_logged_in + if !session[:user_id] + flash[:alert] = ["You need to be logged in to do that!"] + redirect_to new_session_url + end + end + + def ensure_user_reservation + if session[:user_id] != @user.user_id + flash[:alert] = ["Would you like to contiune with your reservations?"] + redirect_to root_path + end + end + end diff --git a/app/controllers/reservations_controller.rb b/app/controllers/reservations_controller.rb new file mode 100644 index 00000000..d3df5ee0 --- /dev/null +++ b/app/controllers/reservations_controller.rb @@ -0,0 +1,52 @@ +class ReservationsController < ApplicationController + before_action :ensure_logged_in, only: [:create, :edit, :destroy] + # before_action :load_restaurant + + def index + @reservations = Reservations.all + end + + def show + @resevation = Reservation.find(params[:id]) + end + + def new + @reservation = Reservation.new + end + + def edit + @resevation = Reservation.find(params[:id]) + end + + def create + @reservaiton = Reservation.new + + @reservaiton.name = params[:reservation][:name] + @reservaiton.date = params[:reservation][:date] + @reservaiton.number_of_people = params[:reservation][:number_of_people] + if @resevation.save + redirect_to resturants_path, notice: 'Reservation have succesfully been booked' + else + render 'restaurants' + end + end + def update + @reservation = Reservation.find(params[:id]) + + @reservaiton.name = params[:reservation][:name] + @reservaiton.date = params[:reservation][:date] + @reservaiton.number_of_people = params[:reservation][:number_of_people] + + if @resevation.save + redirect_to resturants_path, notice: 'Resevations have succesfully been updated ' + else + render :edit + end + end + + def destroy + @reservaiton = Reservation.find(params[:id]) + @reservaiton.destory + redirect_to "/resturants" + end +end diff --git a/app/controllers/restaurants_controller.rb b/app/controllers/restaurants_controller.rb new file mode 100644 index 00000000..0e0b9d22 --- /dev/null +++ b/app/controllers/restaurants_controller.rb @@ -0,0 +1,92 @@ +class RestaurantsController < ApplicationController + + def index + @restaurants = Restaurant.all + end + + def new + @restaurant = Restaurant.new + end + + def create +@restaurant = Restaurant.new +@restaurant.name = params[:restaurant][:name] +@restaurant.address = params[:restaurant][:address] +@restaurant.capacity = params[:restaurant][:capacity] +@restaurant.menu = params[:restaurant][:menu] +@restaurant.summary = params[:restaurant][:summary] +@restaurant.price = params[:restaurant][:price] +@restaurant.owner_id = params[:restaurant][:owner_id] + +@restaurant.open_time = params[:restaurant][:open_time] +@restaurant.close_time = params[:restaurant][:close_time] + +# @restaurant.user_id = current_user.id +# @restaurant.close_time = Time.utc(params[:restaurant]["close_time(1i)"].to_i, +# params[:restaurant]["close_time(2i)"].to_i, +# params[:restaurant]["close_time(3i)"].to_i, +# params[:restaurant]["close_time(4i)"].to_i, +# params[:restaurant]["close_time(5i)"].to_i) +# @restaurant.open_time = Time.utc(params[:restaurant]["open_time(1i)"].to_i, +# params[:restaurant]["open_time(2i)"].to_i, +# params[:restaurant]["open_time(3i)"].to_i, +# params[:restaurant]["open_time(4i)"].to_i, +# params[:restaurant]["open_time(5i)"].to_i) + if @restaurant.save + redirect_to restaurants_path notice: 'Restaurant created ' + + else + render :new + end + end + + + + def show + @restaurant = Restaurant + end + + + + def edit + @restaurant = Restaurant.find(params[:id]) + end + + def update + @restaurant = Restaurant.find(params[:id]) + @restaurant = Restaurant.new + @restaurant.name = params[:restaurant][:name] + @restaurant.address = params[:restaurant][:address] + @restaurant.capacity = params[:restaurant][:capacity] + @restaurant.menu = params[:restaurant][:menu] + @restaurant.summary = params[:restaurant][:summary] + @restaurant.price = params[:restaurant][:price] + @restaurant.owner_id = params[:restaurant][:owner_id] + + @restaurant.open_time = params[:restaurant][:open_time] + @restaurant.close_time = params[:restaurant][:close_time] + + # @restaurant.user_id = current_user.id + @restaurant.close_time = Time.utc(params[:restaurant]["close_time(1i)"].to_i, + params[:restaurant]["close_time(2i)"].to_i, + params[:restaurant]["close_time(3i)"].to_i, + params[:restaurant]["close_time(4i)"].to_i, + params[:restaurant]["close_time(5i)"].to_i) + @restaurant.open_time = Time.utc(params[:restaurant]["open_time(1i)"].to_i, + params[:restaurant]["open_time(2i)"].to_i, + params[:restaurant]["open_time(3i)"].to_i, + params[:restaurant]["open_time(4i)"].to_i, + params[:restaurant]["open_time(5i)"].to_i) + if @restaurant.save + redirect_to restaurants_path, notice: 'Restaurant updated' + else + render :edit + end + end + + def destroy + @restaurant.destroy + redirect_to restaurants_path + end + +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 00000000..de6b71c5 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,21 @@ +class SessionsController < ApplicationController + + def new + end + + def create + user = User.find_by(email: params [:email]) + if user && user.authenticate(params [:password]) + session[:user_id] = user.id + redirect_to user_url, notice: "Logged in!" + else + flash[:notice] = "Invalid email or password" + render "new" + end + end + + def destory + session[:user_id] = nil + redirect_to user_url, notice: "Logged out!" + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 00000000..7f488718 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,24 @@ +class UsersController < ApplicationController + + def new + @user = User.new + end + + def create + @user = User.new + @user.name = params[:user][:name] + @user.email = params[:user][:email] + @user.password = params[:user][:password] + @user.password_confirmation = params[:user][:password_confirmation] + @user.phone_number = params[:user][:phone_number] + + puts "********" + p @user + + if @user.save + redirect_to users_url + else + render :new + end + end +end diff --git a/app/helpers/reservation_helper.rb b/app/helpers/reservation_helper.rb new file mode 100644 index 00000000..a7eb8525 --- /dev/null +++ b/app/helpers/reservation_helper.rb @@ -0,0 +1,2 @@ +module ReservationHelper +end diff --git a/app/helpers/restaurant_helper.rb b/app/helpers/restaurant_helper.rb new file mode 100644 index 00000000..fbcf5e31 --- /dev/null +++ b/app/helpers/restaurant_helper.rb @@ -0,0 +1,2 @@ +module RestaurantHelper +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/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 00000000..0147c3fe --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +end diff --git a/app/models/owner.rb b/app/models/owner.rb new file mode 100644 index 00000000..d0a72063 --- /dev/null +++ b/app/models/owner.rb @@ -0,0 +1,2 @@ +class Owner < ApplicationRecord +end diff --git a/app/models/reservation.rb b/app/models/reservation.rb new file mode 100644 index 00000000..773f0c86 --- /dev/null +++ b/app/models/reservation.rb @@ -0,0 +1,2 @@ +class Reservation < ApplicationRecord +end diff --git a/app/models/restaurant.rb b/app/models/restaurant.rb new file mode 100644 index 00000000..ee1243c7 --- /dev/null +++ b/app/models/restaurant.rb @@ -0,0 +1,2 @@ +class Restaurant < ApplicationRecord +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..987cde92 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ApplicationRecord + has_secure_password +end diff --git a/lib/assets/.keep b/app/views/reservations/form_reservation.html.erb similarity index 100% rename from lib/assets/.keep rename to app/views/reservations/form_reservation.html.erb diff --git a/app/views/reservations/index.html.erb b/app/views/reservations/index.html.erb new file mode 100644 index 00000000..0a923abc --- /dev/null +++ b/app/views/reservations/index.html.erb @@ -0,0 +1,10 @@ +<% @reservations.each do |reservation| %> +
+ <%= reservation.restaurant.name %> + <%= reservation.customer.name %> + <%= reservation.time %> + <%= reservation.restaurant.location %> + <%= reservation.size %> + <%= reservation.created_at %> +
+<% end %> diff --git a/app/views/reservations/new.html.erb b/app/views/reservations/new.html.erb new file mode 100644 index 00000000..0f720528 --- /dev/null +++ b/app/views/reservations/new.html.erb @@ -0,0 +1,45 @@ +

Book a New Reservation

+ +<%= form_for(@reservation) do |f| %> + +

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

+

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

+

+ <%= f.label :date %>
+ <%= f.date_field :date %> +

+

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

+

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

+ +

+ <%= f.submit %> +

+<% end %> + +<%= form_for(@reservation) do |f| %> + <% if @reservation.errors.any? %> +
+

<%= pluralize(@reservation.errors.count, "error") %> prohibited this product from being saved:

+ + +
+ <% end %> +<% end %> + +<%= link_to 'Back', restaurants_path %> diff --git a/lib/tasks/.keep b/app/views/reservations/show.html.erb similarity index 100% rename from lib/tasks/.keep rename to app/views/reservations/show.html.erb diff --git a/app/views/reservations/user_loyalty_points.html.erb b/app/views/reservations/user_loyalty_points.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/restaurants/current_restaurant.html.erb b/app/views/restaurants/current_restaurant.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/restaurants/edit.html.erb b/app/views/restaurants/edit.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb new file mode 100644 index 00000000..67abb65a --- /dev/null +++ b/app/views/restaurants/index.html.erb @@ -0,0 +1 @@ +

index Restaurant

diff --git a/app/views/restaurants/new.html.erb b/app/views/restaurants/new.html.erb new file mode 100644 index 00000000..56e7170c --- /dev/null +++ b/app/views/restaurants/new.html.erb @@ -0,0 +1,66 @@ +

Create New Restaurant

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

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

+ +

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

+ +

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

+ +

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

+ +

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

+ +

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

+ + + +

+ <%= f.label :open_time %> + <%= f.time_select :open_time, + :minute_step =>30, + :ampm => true %> +

+ +

+ <%= f.label :close_time %> + <%= f.time_select :close_time, + :minute_step =>30, + :ampm => true %> +

+ +

+ <%= f.submit %> +

+ <% if @restaurant.errors.any? %> +
+

<%= pluralize(restaurant.errors.count, "error") %> prohibited this product from being saved:

+ + +
+ <% end %> +<% end %> diff --git a/app/views/restaurants/show.html.erb b/app/views/restaurants/show.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 00000000..f36c98da --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,13 @@ +

Log in

+ + <%= 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/sessions/sessions.html.erb b/app/views/sessions/sessions.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/users/edit_username.html.erb b/app/views/users/edit_username.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/users/form_username_create.html.erb b/app/views/users/form_username_create.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 00000000..fb6e52bf --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,33 @@ +

Create New User

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

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

+ + +

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

+ +

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

+ +

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

+ +

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

+ + <%= f.submit 'Sign Up' %> + +<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/config/routes.rb b/config/routes.rb index 787824f8..efd922d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,15 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + root to: 'restaurants#index' + resources :restaurants + + + get 'sessions/new' => 'sessions#new' + post 'sessions/create' => 'sessions#create' + + + resources :users + resources :reservations + end diff --git a/db/migrate/20180123222244_create_users.rb b/db/migrate/20180123222244_create_users.rb new file mode 100644 index 00000000..30b3d26b --- /dev/null +++ b/db/migrate/20180123222244_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration[5.0] + def change + create_table :users do |t| + + t.string :name + t.string :password_digest + t.string :email + t.string :phone_number + + t.timestamps + end + end +end diff --git a/db/migrate/20180124180823_create_reservations.rb b/db/migrate/20180124180823_create_reservations.rb new file mode 100644 index 00000000..f87a9139 --- /dev/null +++ b/db/migrate/20180124180823_create_reservations.rb @@ -0,0 +1,17 @@ +class CreateReservations < ActiveRecord::Migration[5.0] + def change + create_table :reservations do |t| + + # this is the proper way + # t.belongs_to :user + # t.belongs_to :restaurant + + t.string :user_id + t.string :restaurant_id + t.datetime :when + t.integer :number_of_people + + t.timestamps + end + end +end diff --git a/db/migrate/20180124182405_create_restaurants.rb b/db/migrate/20180124182405_create_restaurants.rb new file mode 100644 index 00000000..9765b83f --- /dev/null +++ b/db/migrate/20180124182405_create_restaurants.rb @@ -0,0 +1,18 @@ +class CreateRestaurants < ActiveRecord::Migration[5.0] + def change + create_table :restaurants do |t| + + t.string :name + t.string :address + t.integer :capacity + t.string :menu + t.text :summary + t.integer :price + # t.integer :owner_id + # t.integer :open_time + # t.integer :close_time + + t.timestamps + end + end +end diff --git a/db/migrate/20180124182711_create_owners.rb b/db/migrate/20180124182711_create_owners.rb new file mode 100644 index 00000000..010d481c --- /dev/null +++ b/db/migrate/20180124182711_create_owners.rb @@ -0,0 +1,13 @@ +class CreateOwners < ActiveRecord::Migration[5.0] + def change + create_table :owners do |t| + + t.string :email + t.string :password_digest + t.string :name + t.string :phone + + t.timestamps + end + end +end diff --git a/db/migrate/20180124191759_add_open_time_to_restaurants.rb b/db/migrate/20180124191759_add_open_time_to_restaurants.rb new file mode 100644 index 00000000..b16a0796 --- /dev/null +++ b/db/migrate/20180124191759_add_open_time_to_restaurants.rb @@ -0,0 +1,6 @@ +class AddOpenTimeToRestaurants < ActiveRecord::Migration[5.0] + def change + add_column :restaurants, :open_time, :integer + add_column :restaurants, :close_time, :integer + end +end diff --git a/db/migrate/20180124193137_reservation_time.rb b/db/migrate/20180124193137_reservation_time.rb new file mode 100644 index 00000000..e0fa543b --- /dev/null +++ b/db/migrate/20180124193137_reservation_time.rb @@ -0,0 +1,17 @@ +class ReservationTime < ActiveRecord::Migration[5.0] + def up + change_table :reservations do |t| + t.date :date + t.integer :time + t.remove :when + end + end + + def down + change_table :reservations do |t| + t.remove :date + t.remove :time + t.datetime :when + end + end +end diff --git a/db/migrate/schema.rb b/db/migrate/schema.rb new file mode 100644 index 00000000..3380e96c --- /dev/null +++ b/db/migrate/schema.rb @@ -0,0 +1,53 @@ +# 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: 20180124182711) do + + create_table "owners", force: :cascade do |t| + t.string "email" + t.string "password_digest" + t.string "name" + t.string "phone" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "reservations", force: :cascade do |t| + t.string "user_id" + t.string "restaurant_id" + t.datetime "when" + t.integer "number_of_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.integer "capacity" + t.string "address" + t.integer "price" + t.text "description" + t.integer "owner_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "password_digest" + t.string "email" + t.string "phone_number" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..d492d3fb --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,57 @@ +# 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: 20180124193137) do + + create_table "owners", force: :cascade do |t| + t.string "email" + t.string "password_digest" + t.string "name" + t.string "phone" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "reservations", force: :cascade do |t| + t.string "user_id" + t.string "restaurant_id" + t.integer "number_of_people" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.date "date" + t.integer "time" + end + + create_table "restaurants", force: :cascade do |t| + t.string "name" + t.string "address" + t.integer "capacity" + t.string "menu" + t.text "summary" + t.integer "price" + t.integer "owner_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "open_time" + t.integer "close_time" + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "password_digest" + t.string "email" + t.string "phone_number" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/log/lib/assets/.keep b/log/lib/assets/.keep new file mode 100644 index 00000000..e69de29b diff --git a/log/lib/tasks/.keep b/log/lib/tasks/.keep new file mode 100644 index 00000000..e69de29b diff --git a/test/controllers/reservation_controller_test.rb b/test/controllers/reservation_controller_test.rb new file mode 100644 index 00000000..b67b97d4 --- /dev/null +++ b/test/controllers/reservation_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ReservationControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/restaurant_controller_test.rb b/test/controllers/restaurant_controller_test.rb new file mode 100644 index 00000000..ed137da8 --- /dev/null +++ b/test/controllers/restaurant_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RestaurantControllerTest < 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/user_controller_test.rb b/test/controllers/user_controller_test.rb new file mode 100644 index 00000000..314cd5a4 --- /dev/null +++ b/test/controllers/user_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/owners.yml b/test/fixtures/owners.yml new file mode 100644 index 00000000..80aed36e --- /dev/null +++ b/test/fixtures/owners.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/reservations.yml b/test/fixtures/reservations.yml new file mode 100644 index 00000000..80aed36e --- /dev/null +++ b/test/fixtures/reservations.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/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..80aed36e --- /dev/null +++ b/test/fixtures/users.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/models/owner_test.rb b/test/models/owner_test.rb new file mode 100644 index 00000000..d857cee8 --- /dev/null +++ b/test/models/owner_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OwnerTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/reservation_test.rb b/test/models/reservation_test.rb new file mode 100644 index 00000000..391559fd --- /dev/null +++ b/test/models/reservation_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ReservationTest < 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