add checksum for menu sync
This commit is contained in:
@@ -4,8 +4,25 @@ class Api::Restaurant::MenuController < Api::ApiController
|
||||
# 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
|
||||
param_checksum = params[:checksum]
|
||||
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
|
||||
|
||||
all_menu = Menu.all
|
||||
|
||||
# to hash
|
||||
menu_array = []
|
||||
all_menu.each do |m|
|
||||
menu_array.push(m.to_json(:include => {:menu_categories => { :include => { :menu_items => { :include => [:menu_item_sets, :menu_item_instances => {:include => :menu_instance_item_sets}]} } }}))
|
||||
end
|
||||
|
||||
#export Checksum file generate by md5
|
||||
menu_checksum = Digest::MD5.hexdigest(menu_array.to_json)
|
||||
|
||||
if menu_checksum != param_checksum
|
||||
response.headers['CHECKSUM'] = menu_checksum
|
||||
@menus = all_menu
|
||||
end
|
||||
# @current_menu = Menu.current_menu
|
||||
end
|
||||
|
||||
#Description
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MenuItemAttribute < ApplicationRecord
|
||||
validates_presence_of :attribute_type, :name, :value
|
||||
def self.collection
|
||||
MenuItemAttribute.select("name, value").map { |e| [e.name, e.value] }
|
||||
MenuItemAttribute.select("name").map { |e| [e.name, e.name] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,5 +17,4 @@ if (menu.menu_categories)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,14 +5,14 @@ param_count = item.item_attributes.count
|
||||
item.item_attributes.each do|attr_id|
|
||||
menu_attr = MenuItemAttribute.find(attr_id)
|
||||
if attr_format.count == 0
|
||||
attr_format.push({ type: menu_attr.attribute_type, value: [] })
|
||||
attr_format.push({ type: menu_attr.attribute_type, values: [] })
|
||||
end
|
||||
|
||||
attr_format.each do |af|
|
||||
if menu_attr.attribute_type == af[:type]
|
||||
af[:value].push(menu_attr.value)
|
||||
af[:values].push(menu_attr.name)
|
||||
else
|
||||
new_attr = {type: menu_attr.attribute_type, value: [ menu_attr.value ] }
|
||||
new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] }
|
||||
attr_format.push(new_attr)
|
||||
end
|
||||
|
||||
@@ -29,14 +29,14 @@ param_count = item.item_options.count
|
||||
item.item_options.each do|opt|
|
||||
menu_opt = MenuItemOption.find(opt)
|
||||
if opt_format.count == 0
|
||||
opt_format.push({ type: menu_opt.option_type, value: [] })
|
||||
opt_format.push({ type: menu_opt.option_type, values: [] })
|
||||
end
|
||||
|
||||
opt_format.each do |af|
|
||||
if menu_opt.option_type == af[:type]
|
||||
af[:value].push(menu_opt.value)
|
||||
af[:values].push(menu_opt.name)
|
||||
else
|
||||
new_attr = {type: menu_opt.option_type, value: [ menu_opt.value ] }
|
||||
new_attr = {type: menu_opt.option_type, values: [ menu_opt.name ] }
|
||||
opt_format.push(new_attr)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
json.array! @menus do |menu|
|
||||
menu_json = json.array! @menus do |menu|
|
||||
json.id menu.id
|
||||
json.name menu.name
|
||||
json.valid_days menu.valid_days
|
||||
@@ -12,3 +12,4 @@ json.array! @menus do |menu|
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user