API login/logout with http header token

This commit is contained in:
Min Zeya Phyo
2017-04-15 12:52:40 +06:30
parent 5ca9615e38
commit 355f4fadb0
11 changed files with 67 additions and 86 deletions

View File

@@ -1,28 +1,35 @@
class Api::Restaurant::MenuController < Api::ApiController
before :authenticate_token
#Description
# Pull the default menu details and also other available (active) menus
# Input Params - order_id
def index
menu_detail()
@menu = menu_detail()
end
#Description
# This API show current order details
# Input Params - menu_id
def show
menu_detail(params[:menu_id])
@menu = menu_detail(params[:id])
end
private
def menu_detail
def menu_detail (menu_id)
if (menu_id)
#Pull this menu
menu = Menu.find_by_id(menu_id)
return menu
else
#Pull Default menu
end
end
def menu_params()
params.permit(:id)
end

View File

@@ -1,27 +0,0 @@
class Api::Restaurant::RoomsController < Api::ApiController
before_action :set_room, only: [:show]
def index
render json: Room.active.order("order_by")
end
# Description
# This API full the current status of table and if there is order attached to this table - Order_ID will be return
# Output
# status: {available, cleaning, occupied, reserved}, order_id : <current_order_id>
def show
end
def bill
end
def move
end
private
# Use callbacks to share common setup or constraints between actions.
def set_room
@table = Room.find(params[:id])
end
end

View File

@@ -1,28 +0,0 @@
class Api::Restaurant::SeatingsController < Api::ApiController
before_action :set_table, only: [:show]
def index
render json: Table.active.order("order_by")
end
# Description
# This API full the current status of table and if there is order attached to this table - Order_ID will be return
# Output
# status: {available, cleaning, occupied, reserved}, order_id : <current_order_id>
def show
end
def bill
end
def move
end
private
# Use callbacks to share common setup or constraints between actions.
def set_table
@table = Table.find(params[:id])
end
end

View File

@@ -1,7 +1,16 @@
class Api::Restaurant::ZonesController < Api::ApiController
def index
render json: Zone.includes([:tables, :rooms]).where("is_active = true")
if (params[:filter] && params[:filter] = "all" )
@all_tables = Table.active
@all_rooms = Room.active
else
@zones = Zone.includes([:tables, :rooms]).where("is_active = true")
end
end
private
def zones_params
params.permit(:filter)
end
end

View File

@@ -16,8 +16,11 @@ module TokenVerification
def authenticate_token
authenticate_with_http_token do |token, options|
#@current_user = User.find_by(api_key: token)
@user = Employee.authenticate_token(token)
Rails.logger.debug "token - " + token.to_s
@user = Employee.authenticate_by_token(token)
if @user
return true
#Maybe log - login?
end

View File

@@ -1,6 +1,17 @@
class DiningFacility < ApplicationRecord
belongs_to :zone
default_scope { order('order_by asc') }
scope :active, -> {where(is_active: true)}
def get_current_booking
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='occupied' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
if booking.count > 0 then
return booking[0]
else
return nil
end
end
end

View File

@@ -2,9 +2,11 @@ class MenuCategory < ApplicationRecord
belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
has_many :menu_items
validates_presence_of :name
default_scope { order('order_by asc') }
end

View File

@@ -1,7 +1,9 @@
class MenuItem < ApplicationRecord
belongs_to :menu_category
has_many :menu_item_instances
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id"
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
default_scope { order('item_code asc') }
end

View File

@@ -18,28 +18,23 @@ Rails.application.routes.draw do
namespace :restaurant do
get 'zones' => "zones#index"
get "menu" => "menu#index"
get "menu/:id" => "menu#show"
resources :seatings, only:[:index, :show] do
post 'bill' => "seatings#create"
post 'move' => "seatings#move"
end
resources :rooms, only:[:index, :show] do
post 'bill' => "seatings#create"
post 'move' => "seatings#move"
end
#Menu Related api
resources :menu, only: [:index, :show] do
resources :menu_categories, only: [:index]
resources :menu_items, only: [:index, :show]
resources :menu_sold_out, only: [:index]
end
resources :menu_categories, only: [:index]
resources :menu_items, only: [:index, :show]
resources :menu_items_attributes, only: [:index]
resources :menu_sold_out, only: [:index]
end
#User request move table or bills
post "bill/:booking_id" => "bill#create"
post "move" => "move#update"
#Order Controller
resources :orders, only: [:create, :show, :update]
resources :orders, only: [:create, :show, :update] do
post "bill/:orer_id" => "bill#create"
end
#Current active bookings
resources :bookings, only: [:index, :create, :update]
resources :customers, only: [:index, :show, :create, :update]

View File

@@ -3,11 +3,12 @@ class CreateMenuItemInstances < ActiveRecord::Migration[5.0]
create_table :menu_item_instances do |t|
t.references :menu_item, :foreign_key => true, :null => false
t.string :item_instance_code, :null => false
t.string :item_instance_name, :string, :null => false
t.json :attributes
t.decimal :price,:precision => 10, :scale => 2, :null => false, :default => 0.00
t.boolean :is_available, :null => false, :default => true
t.boolean :is_on_promotion, :null => false, :default => false
t.decimal :promotion_price, :precision => 10, :scale => 2, :null => false, :default => 0.00
t.boolean :is_available, :null => false, :default => true
t.timestamps
end
end

View File

@@ -51,9 +51,9 @@ menu_item_type = Lookup.create([{lookup_type:'menu_item_type', name: 'SIMPLE', v
{lookup_type:'menu_item_type', name: 'DIY', value: 'diy'}])
#menu_item_attribute:[size|]
menu_item_attribute_type = Lookup.create([{lookup_type:'menu_item_attribute_type', name: 'Size', value: 'size'},
{lookup_type:'menu_item_attribute_type', name: 'Spicy', value: 'spicy'},
{lookup_type:'menu_item_attribute_type', name: 'Sweetness', value: 'sweetness'}])
menu_item_attribute_type = Lookup.create([{lookup_type:'menu_item_attribute_type', name: 'Size', value: 'size'}])
# {lookup_type:'menu_item_attribute_type', name: 'Spicy', value: 'spicy'},
# {lookup_type:'menu_item_attribute_type', name: 'Sweetness', value: 'sweetness'}])
#Employee Roles
employee_roles = Lookup.create([{lookup_type:'employee_roles', name: 'Cashier', value: 'cashier'},
@@ -66,7 +66,8 @@ employee_roles = Lookup.create([{lookup_type:'employee_roles', name: 'Cashier',
booking_status = Lookup.create([{lookup_type:'booking_status', name: 'Available', value: 'available'},
{lookup_type:'booking_status', name: 'Reserved', value: 'reserved'},
{lookup_type:'booking_status', name: 'Occupied', value: 'occupied'},
{lookup_type:'booking_status', name: 'Cleaning', value: 'cleaning'}])
{lookup_type:'booking_status', name: 'Cleaning', value: 'cleaning'},
{lookup_type:'booking_status', name: 'Moved', value: 'moved'}])
#WALK CUSTOMER - Default CUSTOMER (take key 1)
customer = Customer.create({id:1, name:"WALK-IN", contact_no:"000000000"})
@@ -96,6 +97,7 @@ menu_category4 = MenuCategory.create({menu: menu, name: "Sample Menu Category 4"
#Default Menu items
menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"01001", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 })
menu_item0_instance = MenuItemInstance.create([{item_instance_code:"01001", menu_item: menu_category1_menu_item0, }])
menu_category1_menu_item1 = SimpleMenuItem.create({item_code:"01002", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 })
menu_category1_menu_item2 = SimpleMenuItem.create({item_code:"01003", name: "Default Menu Item Name 2", alt_name: "Alternate Menu Item Name 2",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 })
menu_category1_menu_item3 = SimpleMenuItem.create({item_code:"01004", name: "Default Menu Item Name 3", alt_name: "Alternate Menu Item Name 3",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 })
@@ -103,7 +105,11 @@ menu_category1_menu_item3 = SimpleMenuItem.create({item_code:"01004", name: "Def
menu_category2_menu_item0 = SimpleMenuItem.create({item_code:"02005", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 })
menu_category2_menu_item1 = SimpleMenuItem.create({item_code:"02006", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 })
menu_category2_menu_item2 = SimpleMenuItem.create({item_code:"02007", name: "Default Menu Item Name 2", alt_name: "Alternate Menu Item Name 2",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 3 })
menu_category2_menu_item3 = SimpleMenuItem.create({item_code:"02008", name: "Default Menu Item Name 3", alt_name: "Alternate Menu Item Name 3",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 4 })
menu_item_attribute_size_small = MenuItemAttribute.create({attribute_type:"size", name: "Small", value: "small"})
menu_item_attribute_size_medium = MenuItemAttribute.create({attribute_type:"size",name: "Medium", value: "medium"})
menu_item_attribute_size_large = MenuItemAttribute.create({attribute_type:"size", name: "Large", value: "large"})
#Default Order Queue stations
order_queue_station1 = OrderQueueStation.create({station_name: "Queue Station 1", is_active: true,printer_name: "kitchen_printer", processing_items: JSON.generate(['01001','01002','01003','01004']), print_copy:true, cut_per_item: false, use_alternate_name: false, created_by: "SYSTEM DEFAULT"})