diff --git a/Gemfile b/Gemfile index 0b7a3b30..5e8f9aa1 100644 --- a/Gemfile +++ b/Gemfile @@ -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' @@ -41,4 +41,3 @@ group :development do gem 'spring' gem 'listen' end - diff --git a/Gemfile.lock b/Gemfile.lock index 2ecff3a1..6b4e2375 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -160,6 +161,7 @@ PLATFORMS ruby DEPENDENCIES + bcrypt (~> 3.1.7) byebug jbuilder (~> 2.0) jquery-rails @@ -173,4 +175,4 @@ DEPENDENCIES web-console BUNDLED WITH - 1.16.1 + 1.16.2 diff --git a/app/assets/javascripts/reservations.js b/app/assets/javascripts/reservations.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/reservations.js @@ -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. diff --git a/app/assets/javascripts/restaurants.js b/app/assets/javascripts/restaurants.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/restaurants.js @@ -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. diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/sessions.js @@ -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. diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/users.js @@ -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. diff --git a/app/assets/stylesheets/reservations.scss b/app/assets/stylesheets/reservations.scss new file mode 100644 index 00000000..7b399eed --- /dev/null +++ b/app/assets/stylesheets/reservations.scss @@ -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/ diff --git a/app/assets/stylesheets/restaurants.scss b/app/assets/stylesheets/restaurants.scss new file mode 100644 index 00000000..18555c87 --- /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..ac0710eb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/reservations_controller.rb b/app/controllers/reservations_controller.rb new file mode 100644 index 00000000..6308e2c6 --- /dev/null +++ b/app/controllers/reservations_controller.rb @@ -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 diff --git a/app/controllers/restaurants_controller.rb b/app/controllers/restaurants_controller.rb new file mode 100644 index 00000000..2b424324 --- /dev/null +++ b/app/controllers/restaurants_controller.rb @@ -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 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 00000000..d6c46e28 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 00000000..5ad0c7ae --- /dev/null +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/helpers/reservations_helper.rb b/app/helpers/reservations_helper.rb new file mode 100644 index 00000000..f28b699d --- /dev/null +++ b/app/helpers/reservations_helper.rb @@ -0,0 +1,2 @@ +module ReservationsHelper +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/reservation.rb b/app/models/reservation.rb new file mode 100644 index 00000000..cc40c87d --- /dev/null +++ b/app/models/reservation.rb @@ -0,0 +1,4 @@ +class Reservation < 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..4f555485 --- /dev/null +++ b/app/models/restaurant.rb @@ -0,0 +1,4 @@ +class Restaurant < ApplicationRecord + has_many :reservations + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..15a2faf3 --- /dev/null +++ b/app/models/user.rb @@ -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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c32feae9..f766cad5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,6 +6,17 @@ <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> + +
+ <%= 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 %> +
<%= yield %> diff --git a/app/views/reservations/_form.html.erb b/app/views/reservations/_form.html.erb new file mode 100644 index 00000000..6ed7dd6b --- /dev/null +++ b/app/views/reservations/_form.html.erb @@ -0,0 +1,18 @@ +<%= form_for ([restaurant, reservation]) do |f| %> + + +
+ <%= f.label :time %> + <%= f.time_field :time %> +
+ +
+ <%= f.label :number_of_guests %> + <%= f.number_field :number_of_guests %> +
+ +
+ <%= f.submit "Submit" %> +
+ +<% end %> diff --git a/app/views/restaurants/edit.html.erb b/app/views/restaurants/edit.html.erb new file mode 100644 index 00000000..62290cca --- /dev/null +++ b/app/views/restaurants/edit.html.erb @@ -0,0 +1,53 @@ +

Edit your restaurant

+ +<%= form_for @restaurant do |f| %> +
+ <%= f.label :name %> + <%= f.text_field :name %> +
+ +
+ <%= f.label :address %> + <%= f.text_field :address %> +
+ +
+ <%= f.label :city %> + <%= f.text_field :city %> +
+ +
+ <%= f.label :price_range %> + <%= f.text_field :price_range %> +
+ +
+ <%= f.label :summary %> + <%= f.text_field :summary %> +
+ +
+ <%= f.label :menu %> + <%= f.text_field :menu %> +
+ +
+ <%= f.label :opening_hours %> + <%= f.time_field :opening_hours %> +
+ +
+ <%= f.label :closing_hours %> + <%= f.time_field :closing_hours %> +
+ + +
+ <%= f.label :capacity %> + <%= f.number_field :capacity %> +
+ +
+ <%= f.submit "Submit" %> +
+<% end %> diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb new file mode 100644 index 00000000..b585b59b --- /dev/null +++ b/app/views/restaurants/index.html.erb @@ -0,0 +1,6 @@ +

Welcome To Munch!

+ +<% @restaurants.each do |restaurant| %> +
  • <%= link_to"#{restaurant.name}", restaurant_url(restaurant) %>
  • + +<% end %> diff --git a/app/views/restaurants/new.html.erb b/app/views/restaurants/new.html.erb new file mode 100644 index 00000000..562e69f9 --- /dev/null +++ b/app/views/restaurants/new.html.erb @@ -0,0 +1,53 @@ +

    Create your restaurant

    + +<%= form_for @restaurant do |f| %> +
    + <%= f.label :name %> + <%= f.text_field :name %> +
    + +
    + <%= f.label :address %> + <%= f.text_field :address %> +
    + +
    + <%= f.label :city %> + <%= f.text_field :city %> +
    + +
    + <%= f.label :price_range %> + <%= f.text_field :price_range %> +
    + +
    + <%= f.label :summary %> + <%= f.text_field :summary %> +
    + +
    + <%= f.label :menu %> + <%= f.text_field :menu %> +
    + +
    + <%= f.label :opening_hours %> + <%= f.time_field :opening_hours %> +
    + +
    + <%= f.label :closing_hours %> + <%= f.time_field :closing_hours %> +
    + + +
    + <%= f.label :capacity %> + <%= f.number_field :capacity %> +
    + +
    + <%= f.submit "Submit" %> +
    +<% end %> diff --git a/app/views/restaurants/show.html.erb b/app/views/restaurants/show.html.erb new file mode 100644 index 00000000..9516b0c9 --- /dev/null +++ b/app/views/restaurants/show.html.erb @@ -0,0 +1,20 @@ +

    <%= @restaurant.name %>

    + +<% if current_user == @restaurant.user %> + <%= link_to "Edit", edit_restaurant_path %> | <%= link_to "Delete", "/restaurants/#{@restaurant.id}", method: :delete %> +<% end %> + + + + +

    Reservation

    +<%= render partial: "reservations/form", locals: {restaurant: @restaurant, reservation: @reservation} %> diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 00000000..13eb063c --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,19 @@ +

    Log in

    + +<%= form_for :session, url: sessions_path do |f| %> + +

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

    + +

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

    + +

    + <%= f.submit "Submit" %> +

    + +<% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 00000000..7e1c3a21 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,29 @@ +

    Sign up

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

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

    + +

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

    + +

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

    + +

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

    + +

    + <%= f.submit "Submit" %> +

    + +<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 00000000..7361344c --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,11 @@ +

    <%= current_user.name %>

    +
    +<%= current_user.email %> +
    + + +<% @restaurants.each do |restaurant| %> +