-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
srinjoyc
committed
Apr 1, 2018
1 parent
f5b65ac
commit 5f2d7b5
Showing
20 changed files
with
577 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class StaticController < ApplicationController | ||
def index | ||
render file: Rails.root.join('public', 'index.html') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
require 'date' | ||
|
||
class Reservation < ApplicationRecord | ||
belongs_to :restaurant | ||
belongs_to :guest | ||
belongs_to :restaurant_table | ||
has_one :restaurant_table | ||
belongs_to :restaurant_shift | ||
|
||
validates_associated :restaurant, :guest, :restaurant_table, :restaurant_shift | ||
validates :guest_count, :reservation_time, :restaurant_id, :restaurant_shift_id, :restaurant_table_id, presence: true | ||
before_save :valid_guest_count | ||
|
||
def self.get_table restaurant_id, time, guest_count | ||
# get reservations 1 hour before and 1 hour after the given time | ||
puts time | ||
reserved_table_ids = ReservedTable.joins(:restaurant_table) | ||
.where(restaurant_id: restaurant_id) | ||
.where(reservation_time: time - 3600...time + 3600) | ||
.pluck(:restaurant_table_id) | ||
|
||
available_tables = RestaurantTable.where(restaurant_id: restaurant_id) | ||
.where('minimum_count <= ? AND maximum_count >= ?', guest_count, guest_count) | ||
.where.not(id: reserved_table_ids) | ||
available_tables.first | ||
end | ||
|
||
def self.reserve_table reservation, table | ||
ReservedTable.create!({ | ||
reservation_id: reservation.id, | ||
reservation_time: reservation.reservation_time, | ||
restaurant_id: reservation.restaurant_id, | ||
restaurant_table_id: table.id, | ||
}) | ||
end | ||
|
||
private | ||
|
||
def valid_guest_count | ||
guest_count > 0 | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ReservedTable < ApplicationRecord | ||
belongs_to :restaurant | ||
belongs_to :restaurant_table | ||
belongs_to :reservation | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
class Restaurant < ApplicationRecord | ||
has_many :restaurant_tables, :dependent => :destroy | ||
has_many :restaurant_shifts, :dependent => :destroy | ||
has_many :reservations, :dependent => :destroy | ||
validates :name, :email, :phone_number, presence: true | ||
validates :email, uniqueness: true, format: { with: /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i } | ||
validates :email, uniqueness: true, | ||
format: { with: /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i } | ||
|
||
def get_shift time | ||
hour = time.hour | ||
puts "-----------------" | ||
puts hour | ||
shift = self.restaurant_shifts.where("start_time >= ? AND end_time >= ?", hour, hour + 1).first | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
RailsAdmin.config do |config| | ||
|
||
### Popular gems integration | ||
|
||
## == Devise == | ||
# config.authenticate_with do | ||
# warden.authenticate! scope: :user | ||
# end | ||
# config.current_user_method(&:current_user) | ||
|
||
## == Cancan == | ||
# config.authorize_with :cancan | ||
|
||
## == Pundit == | ||
# config.authorize_with :pundit | ||
|
||
## == PaperTrail == | ||
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0 | ||
|
||
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration | ||
|
||
## == Gravatar integration == | ||
## To disable Gravatar integration in Navigation Bar set to false | ||
# config.show_gravatar = true | ||
|
||
config.actions do | ||
dashboard # mandatory | ||
index # mandatory | ||
new | ||
export | ||
bulk_delete | ||
show | ||
edit | ||
delete | ||
show_in_app | ||
|
||
## With an audit adapter, you can add: | ||
# history_index | ||
# history_show | ||
end | ||
end |
Oops, something went wrong.