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

Reservation #80

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8f42f15
[Munch] created the skeleton which has the model, association, and co…
d-ang1993 Oct 10, 2018
de7cd5e
[Munch] Sign-up page controller, view created, and b-crypt installed,…
d-ang1993 Oct 10, 2018
bead93a
[Munch] removed column owner within users table
d-ang1993 Oct 10, 2018
2f47590
Added restaurant index page from seeds
Kevintudiep Oct 10, 2018
67a11ec
[Munch] completed log-in controller and view
d-ang1993 Oct 10, 2018
f153b6e
Merge pull request #1 from DangAsian/session_user
ndelforno Oct 10, 2018
4a4b506
Merge pull request #2 from DangAsian/Index_layout
ndelforno Oct 10, 2018
0c0ac2c
added name column to restaurants
Kevintudiep Oct 10, 2018
af9d88a
home login and signup button done
ndelforno Oct 10, 2018
8e76789
Changed Index page to show list restaurants, added individual show pa…
Kevintudiep Oct 10, 2018
77b5dc4
[munch] initialize current_user added log out
ndelforno Oct 10, 2018
697355e
Merge pull request #3 from DangAsian/layout_creation
ndelforno Oct 11, 2018
ff19159
Merge pull request #4 from DangAsian/adding_show_page
ndelforno Oct 11, 2018
9102bca
created restaurant show, edit, create methods in restaurant controlle…
Kevintudiep Oct 11, 2018
a3fda88
Added destroy method in restaurant controller
Kevintudiep Oct 11, 2018
be501dd
reservation party time form
gitmamhub Oct 11, 2018
354b00f
Merge pull request #5 from DangAsian/restaurant_create
ndelforno Oct 11, 2018
04a9504
Changed index layout
ndelforno Oct 11, 2018
d621596
Displayed list of restaurants in user profile
ndelforno Oct 11, 2018
b66cd6c
Edit restaurant from profile page
ndelforno Oct 11, 2018
547af17
[Munch] added the reservation form:
gitmamhub Oct 11, 2018
19997c2
Merge pull request #6 from DangAsian/RO_managment
ndelforno Oct 11, 2018
6e428a6
Merge branch 'master' into reservation
d-ang1993 Oct 11, 2018
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
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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'
Expand All @@ -41,4 +41,3 @@ group :development do
gem 'spring'
gem 'listen'
end

4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
bcrypt (3.1.12)
bindex (0.5.0)
builder (3.2.3)
byebug (10.0.2)
Expand Down Expand Up @@ -160,6 +161,7 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1.7)
byebug
jbuilder (~> 2.0)
jquery-rails
Expand All @@ -173,4 +175,4 @@ DEPENDENCIES
web-console

BUNDLED WITH
1.16.1
1.16.2
2 changes: 2 additions & 0 deletions app/assets/javascripts/reservations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
2 changes: 2 additions & 0 deletions app/assets/javascripts/restaurants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
2 changes: 2 additions & 0 deletions app/assets/javascripts/sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
2 changes: 2 additions & 0 deletions app/assets/javascripts/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/reservations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Reservations controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/restaurants.scss
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.scss
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -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/
12 changes: 12 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ 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
74 changes: 74 additions & 0 deletions app/controllers/reservations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class ReservationsController < ApplicationController
#
# def create_reservation(user_id,rest_id,start_time, end_time, no_of_guests )
# max_time = 1
# current_cap = max_cap
# reservation.restaurant_id = params[][]
# reservation.user_id = params[][]
# reservation.time = params[][]
# reservation.number_of_guests = params[]
#
#
#
# if (restaurant.capacity > no_of_guests) && (time) && current_day == true
#
# allow the party
# current_cap =
# else
#
# reservation request cancelled
#
# end
#


#
# def capacity
# @capacity = Restaurant.find(params[:restaurant_id]).capacity
# end

# end #create reservation ends


def create
@reservation = Reservation.new
@reservation.time = params[:reservation][:time]
@reservation.number_of_guests = params[:reservation][:number_of_guests]
@reservation.user_id = params[:reservation][:user_id]
@reservation.restaurant_id = params[:reservation][:restaurant_id]


@restaurant_total_capacity = Restaurant.find(params[:restaurant_id]).capacity

@restaurant_open =


if (@restaurant_total_capacity < @reservation.number_of_guests)&&()
puts "NOPE"
else
puts "OKAY"
redirect_to restaurants_url
end

end


def edit

end


def update

end




def delete

end



end
66 changes: 66 additions & 0 deletions app/controllers/restaurants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class RestaurantsController < ApplicationController

def index
@restaurants = Restaurant.all
end

def show
@restaurant = Restaurant.find(params[:id])
@reservations = Reservation.where(restaurant_id: @restaurant_id)
@reservations = @restaurant.reservations
@reservation = Reservation.new
end

def new
@restaurant = Restaurant.new
end

def create
@restaurant = Restaurant.new
@restaurant.name = params[:restaurant][:name]
@restaurant.address = params[:restaurant][:address]
@restaurant.city = params[:restaurant][:city]
@restaurant.price_range = params[:restaurant][:price_range]
@restaurant.summary = params[:restaurant][:summary]
@restaurant.menu = params[:restaurant][:menu]
@restaurant.opening_hours = params[:restaurant][:opening_hours]
@restaurant.closing_hours = params[:restaurant][:closing_hours]
@restaurant.capacity = params[:restaurant][:capacity]
@restaurant.user = current_user
if @restaurant.save
redirect_to restaurants_url
else
render :new
end
end

def edit
@restaurant = Restaurant.find(params[:id])
end

def update
@restaurant = Restaurant.find(params[:id])
@restaurant.name = params[:restaurant][:name]
@restaurant.address = params[:restaurant][:address]
@restaurant.city = params[:restaurant][:city]
@restaurant.price_range = params[:restaurant][:price_range]
@restaurant.summary = params[:restaurant][:summary]
@restaurant.menu = params[:restaurant][:menu]
@restaurant.opening_hours = params[:restaurant][:opening_hours]
@restaurant.closing_hours = params[:restaurant][:closing_hours]
@restaurant.capacity = params[:restaurant][:capacity]
if @restaurant.save
redirect_to restaurant_url
else
render :edit
end
end

def destroy
@restaurant = Restaurant.find(params[:id])
@restaurant.destroy
redirect_to restaurants_url
end


end
20 changes: 20 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class SessionsController < ApplicationController
def new
end

def create
user = User.find_by(email: params[:session][:email])
if user && user.authenticate(params[:session][:password])
session[:user_id] = user.id

redirect_to restaurants_url
else
render :new
end
end

def destroy
session[:user_id] = nil
redirect_to restaurants_url, notice: "Logged out!"
end
end
25 changes: 25 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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]


if @user.save
redirect_to restaurants_url
else
render :new
end
end

def show
@restaurants = current_user.restaurants
end

end
2 changes: 2 additions & 0 deletions app/helpers/reservations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ReservationsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/restaurants_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module RestaurantsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SessionsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
4 changes: 4 additions & 0 deletions app/models/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Reservation < ApplicationRecord
belongs_to :restaurant
belongs_to :user
end
4 changes: 4 additions & 0 deletions app/models/restaurant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Restaurant < ApplicationRecord
has_many :reservations
belongs_to :user
end
11 changes: 11 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class User < ApplicationRecord
has_many :reservations
has_many :restaurants

has_secure_password

validates :name, presence: true
validates :email, presence: true


end
11 changes: 11 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>

<header>
<%= link_to 'Home', restaurants_path %>

<% if current_user %>
Signed in as <%= current_user.email %> <%= link_to 'Log out', session_path("current"), :method => :delete %>
<%= link_to 'Create Restaurant', new_restaurant_path %>
<% else %>
<%= link_to 'Log In', new_session_path %> | <%= link_to 'Sign Up', new_user_path %>
<% end %>
</header>
<body>

<%= yield %>
Expand Down
18 changes: 18 additions & 0 deletions app/views/reservations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%= form_for ([restaurant, reservation]) do |f| %>


<div class="field">
<%= f.label :time %>
<%= f.time_field :time %>
</div>

<div class="field_1">
<%= f.label :number_of_guests %>
<%= f.number_field :number_of_guests %>
</div>

<div class="submit">
<%= f.submit "Submit" %>
</div>

<% end %>
53 changes: 53 additions & 0 deletions app/views/restaurants/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<h1>Edit your restaurant</h1>

<%= form_for @restaurant do |f| %>
<div class="">
<%= f.label :name %>
<%= f.text_field :name %>
</div>

<div class="">
<%= f.label :address %>
<%= f.text_field :address %>
</div>

<div class="">
<%= f.label :city %>
<%= f.text_field :city %>
</div>

<div class="">
<%= f.label :price_range %>
<%= f.text_field :price_range %>
</div>

<div class="">
<%= f.label :summary %>
<%= f.text_field :summary %>
</div>

<div class="">
<%= f.label :menu %>
<%= f.text_field :menu %>
</div>

<div class="">
<%= f.label :opening_hours %>
<%= f.time_field :opening_hours %>
</div>

<div class="">
<%= f.label :closing_hours %>
<%= f.time_field :closing_hours %>
</div>


<div class="">
<%= f.label :capacity %>
<%= f.number_field :capacity %>
</div>

<div class="">
<%= f.submit "Submit" %>
</div>
<% end %>
Loading