menu and menu item categories
This commit is contained in:
15
app/controllers/api/bill_controller.rb
Normal file
15
app/controllers/api/bill_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Api::Restaurant::BillController < Api::ApiController
|
||||
|
||||
|
||||
#Create invoice based on booking
|
||||
#Output and invoice
|
||||
def create
|
||||
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def bill_params
|
||||
params.permit(:booking_id, :order_id)
|
||||
end
|
||||
end
|
||||
15
app/controllers/api/move_controller.rb
Normal file
15
app/controllers/api/move_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Api::Restaurant::MoveController < Api::ApiController
|
||||
|
||||
#Move between table
|
||||
def update
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def move_params
|
||||
params.permit(:booking_id, :order_id)
|
||||
end
|
||||
|
||||
end
|
||||
37
app/controllers/api/restaurant/menu_categories.rb
Normal file
37
app/controllers/api/restaurant/menu_categories.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
class Api::Restaurant::MenuController < Api::ApiController
|
||||
|
||||
#Description
|
||||
# Pull the default menu details and also other available (active) menus
|
||||
# Input Params - order_id
|
||||
def index
|
||||
@menus = Menu.all
|
||||
@current_menu = Menu.current_menu
|
||||
|
||||
end
|
||||
|
||||
#Description
|
||||
# This API show current order details
|
||||
# Input Params - menu_id
|
||||
def show
|
||||
@menu = menu_detail(params[:id])
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def menu_detail (menu_id)
|
||||
if (menu_id)
|
||||
#Pull this menu
|
||||
menu = Menu.find_by_id(menu_id)
|
||||
return menu
|
||||
else
|
||||
Menu.current_menu
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def menu_params()
|
||||
params.permit(:id)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -4,7 +4,9 @@ class Api::Restaurant::MenuController < Api::ApiController
|
||||
# Pull the default menu details and also other available (active) menus
|
||||
# Input Params - order_id
|
||||
def index
|
||||
@menu = menu_detail()
|
||||
@menus = Menu.all
|
||||
@current_menu = Menu.current_menu
|
||||
|
||||
end
|
||||
|
||||
#Description
|
||||
@@ -22,8 +24,7 @@ class Api::Restaurant::MenuController < Api::ApiController
|
||||
menu = Menu.find_by_id(menu_id)
|
||||
return menu
|
||||
else
|
||||
#Pull Default menu
|
||||
|
||||
Menu.current_menu
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Api::Restaurant::MenuItemAttributesController < Api::ApiController
|
||||
|
||||
#Description
|
||||
# Pull the default menu details and also other available (active) menus
|
||||
# Input Params - order_id
|
||||
def index
|
||||
@menu_attributes = MenuItemAttribute.all
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class Api::Restaurant::MenuItemOptionsController < Api::ApiController
|
||||
|
||||
#Description
|
||||
# Pull the default menu details and also other available (active) menus
|
||||
# Input Params - order_id
|
||||
def index
|
||||
@menu_options = MenuItemOption.all
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
12
app/controllers/api/restaurant/menu_sold_out.rb
Normal file
12
app/controllers/api/restaurant/menu_sold_out.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Api::Restaurant::MenuSoldOutController < Api::ApiController
|
||||
|
||||
#Description
|
||||
# Pull the default menu details and also other available (active) menus
|
||||
# Input Params - order_id
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -8,40 +8,49 @@ class Employee < ApplicationRecord
|
||||
|
||||
|
||||
def self.login(emp_id, password)
|
||||
user = Employee.find_by_emp_id(emp_id).authenticate(password)
|
||||
|
||||
Rails.logger.debug user
|
||||
|
||||
user = Employee.find_by_emp_id(emp_id)
|
||||
if (user)
|
||||
user.generate_token
|
||||
user.session_expiry = DateTime.now.utc + 30.minutes
|
||||
user.session_last_login = DateTime.now.utc
|
||||
user.save
|
||||
user.authenticate(password)
|
||||
|
||||
return user
|
||||
if (user)
|
||||
user.generate_token
|
||||
user.session_expiry = DateTime.now.utc + 30.minutes
|
||||
user.session_last_login = DateTime.now.utc
|
||||
user.save
|
||||
return user
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return nil
|
||||
|
||||
end
|
||||
|
||||
def self.authenticate_by_token(session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
if user && user.session_expiry.utc > DateTime.now.utc
|
||||
#Extend the login time each time authenticatation take place
|
||||
user.session_expiry = DateTime.now.utc + 30.minutes
|
||||
user.save
|
||||
return true
|
||||
else
|
||||
return false
|
||||
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
if user && user.session_expiry.utc > DateTime.now.utc
|
||||
#Extend the login time each time authenticatation take place
|
||||
user.session_expiry = DateTime.now.utc + 30.minutes
|
||||
user.save
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
def self.logout(session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
if user
|
||||
user.token_session = nil
|
||||
user.session_expiry = nil
|
||||
user.save
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
if user
|
||||
user.token_session = nil
|
||||
user.session_expiry = nil
|
||||
user.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,4 +3,23 @@ class Menu < ApplicationRecord
|
||||
|
||||
validates_presence_of :name,:is_active, :valid_days, :valid_time_from, :valid_time_to
|
||||
|
||||
#Default Scope to pull the active version only
|
||||
default_scope { where(is_active: true).order("created_at desc") }
|
||||
|
||||
def self.current_menu
|
||||
today = DateTime.now
|
||||
day_of_week = today.wday
|
||||
menus = Menu.where("is_active = true and '#{today.strftime("%H:%M")}' between TIME(valid_time_from) and TIME(valid_time_to)")
|
||||
current_menu = nil
|
||||
|
||||
#Loop through the menu which is valid days - get the first menu out and return result
|
||||
menus.each do |menu|
|
||||
if menu.valid_days.include?(day_of_week.to_s)
|
||||
current_menu = menu
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return current_menu
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MenuItem < ApplicationRecord
|
||||
belongs_to :menu_category
|
||||
belongs_to :menu_category, :optional => true
|
||||
has_many :menu_item_instances
|
||||
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
|
||||
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
|
||||
|
||||
20
app/views/api/restaurant/menu/_menu.json.jbuilder
Normal file
20
app/views/api/restaurant/menu/_menu.json.jbuilder
Normal file
@@ -0,0 +1,20 @@
|
||||
json.id menu.id
|
||||
json.name menu.name
|
||||
json.is_active menu.is_active
|
||||
json.valid_time_from menu.valid_time_from.strftime("%H:%M")
|
||||
json.valid_time_to menu.valid_time_to.strftime("%H:%M")
|
||||
|
||||
if (menu.menu_categories)
|
||||
json.menu_categories menu.menu_categories do |category|
|
||||
json.id category.id
|
||||
json.name category.name
|
||||
json.alt_name category.alt_name
|
||||
|
||||
if category.menu_items
|
||||
json.menu_items category.menu_items do |item|
|
||||
json.partial! 'api/restaurant/menu/menu_item', item: item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
40
app/views/api/restaurant/menu/_menu_item.json.jbuilder
Normal file
40
app/views/api/restaurant/menu/_menu_item.json.jbuilder
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#Menu Item Information
|
||||
json.item_code item.item_code
|
||||
json.name item.name
|
||||
json.alt_name item.alt_name
|
||||
json.type item.type
|
||||
json.min_qty item.min_qty
|
||||
json.min_selectable_item item.min_selectable_item
|
||||
json.max_selectable_item item.max_selectable_item
|
||||
|
||||
#Item instance
|
||||
if item.menu_item_instances.count == 1 then
|
||||
|
||||
item_instance = item.menu_item_instances[0]
|
||||
json.price = item_instance.price
|
||||
json.is_available = item_instance.is_available
|
||||
json.is_on_promotion = item_instance.is_on_promotion
|
||||
json.promotion_price = item_instance.promotion_price
|
||||
json.item_attributes = item_instance.item_attributes
|
||||
|
||||
elsif item.menu_item_instances.count > 1 then
|
||||
|
||||
json.item_instances item.menu_item_instances do |is|
|
||||
json.item_instance_item_code = is.item_instance_code
|
||||
json.item_instance_name = is.item_instance_name
|
||||
json.price = is.price
|
||||
json.is_available = is.is_available
|
||||
json.is_on_promotion = is.is_on_promotion
|
||||
json.promotion_price = is.promotion_price
|
||||
json.item_attributes = is.item_attributes
|
||||
end
|
||||
|
||||
end
|
||||
#Child Menu items
|
||||
if (item.children) then
|
||||
json.set_items item.children.each do |item|
|
||||
json.partial! 'api/restaurant/menu/menu_item', item: item
|
||||
end
|
||||
|
||||
end
|
||||
12
app/views/api/restaurant/menu/index.json.jbuilder
Normal file
12
app/views/api/restaurant/menu/index.json.jbuilder
Normal file
@@ -0,0 +1,12 @@
|
||||
json.array! @menus do |menu|
|
||||
json.id menu.id
|
||||
json.name menu.name
|
||||
json.valid_days menu.valid_days
|
||||
json.valid_time_from menu.valid_time_from.strftime("%H:%M")
|
||||
json.valid_time_to menu.valid_time_to.strftime("%H:%M")
|
||||
if (@current_menu)
|
||||
json.current_menu do
|
||||
json.partial! 'api/restaurant/menu/menu', menu: @current_menu
|
||||
end
|
||||
end
|
||||
end
|
||||
3
app/views/api/restaurant/menu/show.json.jbuilder
Normal file
3
app/views/api/restaurant/menu/show.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
||||
if (@menu)
|
||||
json.partial! 'api/restaurant/menu/menu', menu: @menu
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
json.array! @menu_attributes do |attribute|
|
||||
json.type attribute.attribute_type
|
||||
json.name attribute.name
|
||||
json.value attribute.value
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
json.array! @menu_options do |option|
|
||||
json.name option.name
|
||||
json.value option.value
|
||||
end
|
||||
42
app/views/api/restaurant/zones/index.json.jbuilder
Normal file
42
app/views/api/restaurant/zones/index.json.jbuilder
Normal file
@@ -0,0 +1,42 @@
|
||||
if @zones
|
||||
json.array! @zones do |zone|
|
||||
json.id zone.id
|
||||
json.name zone.name
|
||||
#List all tables
|
||||
json.tables zone.tables do |table|
|
||||
json.id table.id
|
||||
json.name table.name
|
||||
json.status table.status
|
||||
json.zone_id table.zone_id #Add this zone_id to keep data structure consistance
|
||||
json.current_booking table.get_current_booking
|
||||
end
|
||||
|
||||
json.rooms zone.rooms do |room|
|
||||
json.id room.id
|
||||
json.name room.name
|
||||
json.status room.status
|
||||
json.zone_id room.zone_id #Add this zone_id to keep data structure consistance
|
||||
json.current_booking room.get_current_booking
|
||||
|
||||
end
|
||||
end
|
||||
else #list all tables and rooms with out zones
|
||||
json.tables @all_tables do |table|
|
||||
json.id table.id
|
||||
json.name table.name
|
||||
json.status table.status
|
||||
json.zone_id table.zone_id #Add this zone_id to keep data structure consistance
|
||||
json.current_booking table.get_current_booking
|
||||
|
||||
end
|
||||
|
||||
json.rooms @all_rooms do |room|
|
||||
json.id room.id
|
||||
json.name room.name
|
||||
json.status room.status
|
||||
json.zone_id room.zone_id #Add this zone_id to keep data structure consistance
|
||||
json.current_booking room.get_current_booking
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user