From 30b4a0f5ff4b20a3965960ba853110645759c203 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Mon, 3 Apr 2017 21:26:22 +0630 Subject: [PATCH] menu, table,rooms, orders structure --- .../api/authenticate_controller.rb | 9 ++++ app/controllers/api/customer_controller.rb | 10 ++++ .../api/restaurant/invoice_controller.rb | 24 +++++++++ .../api/restaurant/menu_controller.rb | 29 +++++++++++ .../api/restaurant/order_controller.rb | 36 +++++++++++++ .../api/restaurant/rooms_controller.rb | 21 ++++++++ .../api/restaurant/seat_tables_controller.rb | 5 -- .../api/restaurant/seatings_controller.rb | 21 ++++++++ .../api/restaurant/takeaway_controller.rb | 21 ++++++++ .../api/restaurant/zones_controller.rb | 1 + app/models/customer.rb | 9 ++++ app/models/dining_facility.rb | 2 + app/models/dining_in.rb | 4 ++ app/models/menu_category.rb | 5 ++ app/models/menu_item.rb | 7 +++ app/models/menu_item_attribute.rb | 4 ++ app/models/menu_item_instance.rb | 4 ++ app/models/menu_item_option.rb | 4 ++ app/models/order.rb | 12 +++++ app/models/order_item.rb | 10 ++++ app/models/room.rb | 5 +- app/models/room_booking.rb | 2 + app/models/room_order.rb | 4 ++ app/models/seat_table.rb | 6 --- app/models/set_menu_item.rb | 3 ++ app/models/simple_menu_item.rb | 3 ++ app/models/table.rb | 4 ++ app/models/zone.rb | 2 +- config/routes.rb | 9 +++- .../20170324135335_create_seat_tables.rb | 15 ------ db/migrate/20170325103022_create_rooms.rb | 13 ----- db/migrate/20170325111608_create_menus.rb | 2 +- .../20170327152733_create_menu_categories.rb | 2 +- .../20170331024749_create_menu_items.rb | 19 +++++++ ...70402083337_create_menu_item_attributes.rb | 11 ++++ ...20170402083525_create_menu_item_options.rb | 10 ++++ ...170402084230_create_menu_item_instances.rb | 14 +++++ db/migrate/20170403135121_create_customers.rb | 15 ++++++ db/migrate/20170403135934_create_orders.rb | 17 +++++++ .../20170403140820_create_order_items.rb | 18 +++++++ ...20170403142424_create_dining_facilities.rb | 16 ++++++ .../20170403143526_create_dining_ins.rb | 11 ++++ .../20170403144732_create_room_bookings.rb | 15 ++++++ .../20170403145042_create_room_orders.rb | 11 ++++ db/schema.txt | 51 ++++++++++++++++--- spec/models/customer_spec.rb | 5 ++ spec/models/dining_facility_spec.rb | 5 ++ spec/models/dining_in_spec.rb | 5 ++ spec/models/menu_category_spec.rb | 15 ++++++ spec/models/menu_item_attribute_spec.rb | 7 +++ spec/models/menu_item_instance_spec.rb | 5 ++ spec/models/menu_item_option_spec.rb | 6 +++ spec/models/menu_item_spec.rb | 5 ++ spec/models/order_item_spec.rb | 5 ++ spec/models/order_spec.rb | 5 ++ spec/models/room_booking_spec.rb | 5 ++ spec/models/room_order_spec.rb | 5 ++ spec/models/room_spec.rb | 10 ---- spec/models/seat_table_spec.rb | 13 ----- .../api/restaurant/seat_tables_spec.rb | 25 --------- 60 files changed, 536 insertions(+), 101 deletions(-) create mode 100644 app/controllers/api/authenticate_controller.rb create mode 100644 app/controllers/api/customer_controller.rb create mode 100644 app/controllers/api/restaurant/invoice_controller.rb create mode 100644 app/controllers/api/restaurant/menu_controller.rb create mode 100644 app/controllers/api/restaurant/order_controller.rb create mode 100644 app/controllers/api/restaurant/rooms_controller.rb delete mode 100644 app/controllers/api/restaurant/seat_tables_controller.rb create mode 100644 app/controllers/api/restaurant/seatings_controller.rb create mode 100644 app/controllers/api/restaurant/takeaway_controller.rb create mode 100644 app/models/customer.rb create mode 100644 app/models/dining_facility.rb create mode 100644 app/models/dining_in.rb create mode 100644 app/models/menu_item.rb create mode 100644 app/models/menu_item_attribute.rb create mode 100644 app/models/menu_item_instance.rb create mode 100644 app/models/menu_item_option.rb create mode 100644 app/models/order.rb create mode 100644 app/models/order_item.rb create mode 100644 app/models/room_booking.rb create mode 100644 app/models/room_order.rb delete mode 100644 app/models/seat_table.rb create mode 100644 app/models/set_menu_item.rb create mode 100644 app/models/simple_menu_item.rb create mode 100644 app/models/table.rb delete mode 100644 db/migrate/20170324135335_create_seat_tables.rb delete mode 100644 db/migrate/20170325103022_create_rooms.rb create mode 100644 db/migrate/20170331024749_create_menu_items.rb create mode 100644 db/migrate/20170402083337_create_menu_item_attributes.rb create mode 100644 db/migrate/20170402083525_create_menu_item_options.rb create mode 100644 db/migrate/20170402084230_create_menu_item_instances.rb create mode 100644 db/migrate/20170403135121_create_customers.rb create mode 100644 db/migrate/20170403135934_create_orders.rb create mode 100644 db/migrate/20170403140820_create_order_items.rb create mode 100644 db/migrate/20170403142424_create_dining_facilities.rb create mode 100644 db/migrate/20170403143526_create_dining_ins.rb create mode 100644 db/migrate/20170403144732_create_room_bookings.rb create mode 100644 db/migrate/20170403145042_create_room_orders.rb create mode 100644 spec/models/customer_spec.rb create mode 100644 spec/models/dining_facility_spec.rb create mode 100644 spec/models/dining_in_spec.rb create mode 100644 spec/models/menu_item_attribute_spec.rb create mode 100644 spec/models/menu_item_instance_spec.rb create mode 100644 spec/models/menu_item_option_spec.rb create mode 100644 spec/models/menu_item_spec.rb create mode 100644 spec/models/order_item_spec.rb create mode 100644 spec/models/order_spec.rb create mode 100644 spec/models/room_booking_spec.rb create mode 100644 spec/models/room_order_spec.rb delete mode 100644 spec/models/room_spec.rb delete mode 100644 spec/models/seat_table_spec.rb delete mode 100644 spec/requests/api/restaurant/seat_tables_spec.rb diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb new file mode 100644 index 00000000..e58f51d7 --- /dev/null +++ b/app/controllers/api/authenticate_controller.rb @@ -0,0 +1,9 @@ +class Api::AuthenticateController < ActionController::API + + def create + end + + def destroy + end + +end diff --git a/app/controllers/api/customer_controller.rb b/app/controllers/api/customer_controller.rb new file mode 100644 index 00000000..4accb5fd --- /dev/null +++ b/app/controllers/api/customer_controller.rb @@ -0,0 +1,10 @@ +class Api::CustomersController < ActionController::API + + #List all active customers by name + def index + end + + #Show customer by ID + def show + end +end diff --git a/app/controllers/api/restaurant/invoice_controller.rb b/app/controllers/api/restaurant/invoice_controller.rb new file mode 100644 index 00000000..a4476ae1 --- /dev/null +++ b/app/controllers/api/restaurant/invoice_controller.rb @@ -0,0 +1,24 @@ +class Api::Restaurant::InvoiceController < ActionController::API + before :authenticate_token + + #Description + # This API show current order details + # Input Params - order_id + def show + order = Order.find(params[:order_id]) + order.order_items + end + + + # Description + # This API allow new invoice creation + # Input Params + # order_id + # Output Params + # Status [Success | Error | System Error] , order_id, error_message (*) + def create + + + end + +end diff --git a/app/controllers/api/restaurant/menu_controller.rb b/app/controllers/api/restaurant/menu_controller.rb new file mode 100644 index 00000000..47a07e8b --- /dev/null +++ b/app/controllers/api/restaurant/menu_controller.rb @@ -0,0 +1,29 @@ +class Api::Restaurant::MenuController < ActionController::API + before :authenticate_token + + #Description + # Pull the default menu details and also other available (active) menus + # Input Params - order_id + def index + menu_detail() + end + + #Description + # This API show current order details + # Input Params - menu_id + def show + menu_detail(params[:menu_id]) + end + + + private + def menu_detail + if (menu_id) + #Pull this menu + else + #Pull Default menu + end + end + + +end diff --git a/app/controllers/api/restaurant/order_controller.rb b/app/controllers/api/restaurant/order_controller.rb new file mode 100644 index 00000000..0fbc9f3f --- /dev/null +++ b/app/controllers/api/restaurant/order_controller.rb @@ -0,0 +1,36 @@ +class Api::Restaurant::OrderController < ActionController::API + before :authenticate_token + + #Description + # This API show current order details + # Input Params - order_id + def show + order = Order.find(params[:order_id]) + order.order_items + end + + + # Description + # This API allow new order creation + # Input Params + # order_source [* default - emenu] | table_id (*require for Dine-In) | order_type [* Default - Dine-in] + # | guest_info (optional) | customer_id (optional) + # order_items {[item_code, item_instance_code , qty, option, variants]} + # Output Params + # Status [Success | Error | System Error] , order_id, error_message (*) + def create + + + end + + # Description + # This API - allow order to add new items to existing orders, does not allow you to remove confirm items + # Update customer info, Guest Info + # Input Params + # order_id , order_items {[item_code, item_instance_code , qty, option, variants]} + def update + + end + + +end diff --git a/app/controllers/api/restaurant/rooms_controller.rb b/app/controllers/api/restaurant/rooms_controller.rb new file mode 100644 index 00000000..9c5108be --- /dev/null +++ b/app/controllers/api/restaurant/rooms_controller.rb @@ -0,0 +1,21 @@ +class Api::Restaurant::RoomsController < ActionController::API + def index + render json: SeatTable.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 : + def show + + end + + #Input Params + # table_id: table_id + # Output + # status: error | success, error_message: + def update + + end +end diff --git a/app/controllers/api/restaurant/seat_tables_controller.rb b/app/controllers/api/restaurant/seat_tables_controller.rb deleted file mode 100644 index 4b470b68..00000000 --- a/app/controllers/api/restaurant/seat_tables_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Api::Restaurant::SeatTablesController < ActionController::API - def index - render json: SeatTable.order("order_by") - end -end diff --git a/app/controllers/api/restaurant/seatings_controller.rb b/app/controllers/api/restaurant/seatings_controller.rb new file mode 100644 index 00000000..37aa5774 --- /dev/null +++ b/app/controllers/api/restaurant/seatings_controller.rb @@ -0,0 +1,21 @@ +class Api::Restaurant::SeatingsController < ActionController::API + def index + render json: Zone.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 : + def show + + end + + #Input Params + # table_id: table_id + # Output + # status: error | success, error_message: + def update + + end +end diff --git a/app/controllers/api/restaurant/takeaway_controller.rb b/app/controllers/api/restaurant/takeaway_controller.rb new file mode 100644 index 00000000..a6988160 --- /dev/null +++ b/app/controllers/api/restaurant/takeaway_controller.rb @@ -0,0 +1,21 @@ +class Api::Restaurant::TakeawaysController < ActionController::API + def index + render json: SeatTable.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 : + def show + + end + + #Input Params + # table_id: table_id + # Output + # status: error | success, error_message: + def update + + end +end diff --git a/app/controllers/api/restaurant/zones_controller.rb b/app/controllers/api/restaurant/zones_controller.rb index 1bbaa3af..e96a8ff2 100644 --- a/app/controllers/api/restaurant/zones_controller.rb +++ b/app/controllers/api/restaurant/zones_controller.rb @@ -1,4 +1,5 @@ class Api::Restaurant::ZonesController < ActionController::API + def index render json: Zone.where("is_active = true") end diff --git a/app/models/customer.rb b/app/models/customer.rb new file mode 100644 index 00000000..e785ef23 --- /dev/null +++ b/app/models/customer.rb @@ -0,0 +1,9 @@ +class Customer < ApplicationRecord + has_many :orders + has_many :sales + + validates_presence_of :name, :contact_no + validates :contact_no, uniqueness: true + + +end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb new file mode 100644 index 00000000..513d3f67 --- /dev/null +++ b/app/models/dining_facility.rb @@ -0,0 +1,2 @@ +class DiningFacility < ApplicationRecord +end diff --git a/app/models/dining_in.rb b/app/models/dining_in.rb new file mode 100644 index 00000000..a7307eca --- /dev/null +++ b/app/models/dining_in.rb @@ -0,0 +1,4 @@ +class DiningIn < ApplicationRecord + belongs_to :table + belongs_to :order +end diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 8ef15958..4d345019 100644 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -1,5 +1,10 @@ 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 + validates_presence_of :name + + end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb new file mode 100644 index 00000000..b5cb8cd3 --- /dev/null +++ b/app/models/menu_item.rb @@ -0,0 +1,7 @@ +class MenuItem < ApplicationRecord + belongs_to :menu_category + has_many :menu_item_instances + belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id" + has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id" + +end diff --git a/app/models/menu_item_attribute.rb b/app/models/menu_item_attribute.rb new file mode 100644 index 00000000..ebaa060e --- /dev/null +++ b/app/models/menu_item_attribute.rb @@ -0,0 +1,4 @@ +class MenuItemAttribute < ApplicationRecord + validates_presence_of :attribute_type, :name, :value + +end diff --git a/app/models/menu_item_instance.rb b/app/models/menu_item_instance.rb new file mode 100644 index 00000000..e7f7775e --- /dev/null +++ b/app/models/menu_item_instance.rb @@ -0,0 +1,4 @@ +class MenuItemInstance < ApplicationRecord + belongs_to :menu_item + +end diff --git a/app/models/menu_item_option.rb b/app/models/menu_item_option.rb new file mode 100644 index 00000000..fdf2d137 --- /dev/null +++ b/app/models/menu_item_option.rb @@ -0,0 +1,4 @@ +class MenuItemOption < ApplicationRecord + validates_presence_of :name, :value + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 00000000..fb7ea2f6 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,12 @@ +class Order < ApplicationRecord + before_create :set_order_date + belongs_to :customer + has_many :order_items, inverse_of: :order + has_many :dining_ins + + + private + def set_order_date + self.date = Time.now.utc + end +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 00000000..4aae01a4 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,10 @@ +class OrderItem < ApplicationRecord + #Associations + belongs_to :order + + #Validation + validates_presence_of :item_code, :item_name, :qty + validates :qty, numericality: { :greater_than 0 } + validates_associated :orders + +end diff --git a/app/models/room.rb b/app/models/room.rb index 7bef4c5f..d99708a3 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -1,6 +1,3 @@ -class Room < ApplicationRecord - belongs_to :zone - - validates_presence_of :name,:seater, :order_by, :created_by, :is_active +class Room < DiningFacility end diff --git a/app/models/room_booking.rb b/app/models/room_booking.rb new file mode 100644 index 00000000..aa2c31c9 --- /dev/null +++ b/app/models/room_booking.rb @@ -0,0 +1,2 @@ +class RoomBooking < ApplicationRecord +end diff --git a/app/models/room_order.rb b/app/models/room_order.rb new file mode 100644 index 00000000..2e8dbf77 --- /dev/null +++ b/app/models/room_order.rb @@ -0,0 +1,4 @@ +class RoomOrder < ApplicationRecord + belongs_to :room + belongs_to :orders +end diff --git a/app/models/seat_table.rb b/app/models/seat_table.rb deleted file mode 100644 index 758545fd..00000000 --- a/app/models/seat_table.rb +++ /dev/null @@ -1,6 +0,0 @@ -class SeatTable < ApplicationRecord - belongs_to :zone - - # validations - validates_presence_of :name,:order_by, :created_by -end diff --git a/app/models/set_menu_item.rb b/app/models/set_menu_item.rb new file mode 100644 index 00000000..da299cd0 --- /dev/null +++ b/app/models/set_menu_item.rb @@ -0,0 +1,3 @@ +class SetMenuItem < MenuItem + +end diff --git a/app/models/simple_menu_item.rb b/app/models/simple_menu_item.rb new file mode 100644 index 00000000..b36d4779 --- /dev/null +++ b/app/models/simple_menu_item.rb @@ -0,0 +1,3 @@ +class SimpleMenuItem < MenuItem + +end diff --git a/app/models/table.rb b/app/models/table.rb new file mode 100644 index 00000000..50897d38 --- /dev/null +++ b/app/models/table.rb @@ -0,0 +1,4 @@ +class Table < DiningFacility + has_many :dining_ins + +end diff --git a/app/models/zone.rb b/app/models/zone.rb index 05ab62f2..e5ad15c7 100644 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -1,6 +1,6 @@ class Zone < ApplicationRecord # model association - has_many :seat_tables, dependent: :destroy + has_many :tables, dependent: :destroy has_many :rooms, dependent: :destroy # validations diff --git a/config/routes.rb b/config/routes.rb index 177afb55..7ae7e768 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,16 @@ Rails.application.routes.draw do namespace :api, :defaults => { :format => 'json' } do + + #Session Login and Logout + post 'autheticate' => "autheticate#create" + delete 'autheticate' => "autheticate#destroy" + namespace :restaurant do get 'zones' => "zones#index" - get 'seat_tables' => "seat_tables#index" + get 'tables' => "#index" end + + end # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html diff --git a/db/migrate/20170324135335_create_seat_tables.rb b/db/migrate/20170324135335_create_seat_tables.rb deleted file mode 100644 index 9b7da5b7..00000000 --- a/db/migrate/20170324135335_create_seat_tables.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateSeatTables < ActiveRecord::Migration[5.0] - def change - create_table :seat_tables do |t| - t.references :zone, foreign_key: true - t.string :name, :null => false - t.integer :order_by - t.integer :no_of_seater, :null => false, :default => 2 - t.string :table_type, :null => false, :default => "square" - t.float :position_x, :null => false, :default => 0.0 - t.float :position_y, :null => false, :default => 0.0 - t.string :created_by - t.timestamps - end - end -end diff --git a/db/migrate/20170325103022_create_rooms.rb b/db/migrate/20170325103022_create_rooms.rb deleted file mode 100644 index 2f153f32..00000000 --- a/db/migrate/20170325103022_create_rooms.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateRooms < ActiveRecord::Migration[5.0] - def change - create_table :rooms do |t| - t.string :name, :null => false - t.integer :seater, :null => false, :default => 4 - t.string :created_by - t.boolean :is_active, :null => false, :default => true - t.integer :order_by - t.references :zone - t.timestamps - end - end -end diff --git a/db/migrate/20170325111608_create_menus.rb b/db/migrate/20170325111608_create_menus.rb index 50752f07..a542de50 100644 --- a/db/migrate/20170325111608_create_menus.rb +++ b/db/migrate/20170325111608_create_menus.rb @@ -2,7 +2,7 @@ class CreateMenus < ActiveRecord::Migration[5.0] def change create_table :menus do |t| t.string :name - t.boolean :is_active, :null => false + t.boolean :is_active, :null => false, :deafult => true t.string :valid_days, :null => false, :default => "1,2,3,4,5,6,7" t.time :valid_time_from, :null => false, :default => "00:00:00" t.time :valid_time_to, :null => false, :default => "23:59:59" diff --git a/db/migrate/20170327152733_create_menu_categories.rb b/db/migrate/20170327152733_create_menu_categories.rb index a6dc0ad6..4d962a48 100644 --- a/db/migrate/20170327152733_create_menu_categories.rb +++ b/db/migrate/20170327152733_create_menu_categories.rb @@ -5,7 +5,7 @@ class CreateMenuCategories < ActiveRecord::Migration[5.0] t.string :name, :null => false t.string :alt_name t.integer :order_by - t.integer :parent_category_id + t.references :menu_category, :null => true t.timestamps end diff --git a/db/migrate/20170331024749_create_menu_items.rb b/db/migrate/20170331024749_create_menu_items.rb new file mode 100644 index 00000000..2a0e8e2e --- /dev/null +++ b/db/migrate/20170331024749_create_menu_items.rb @@ -0,0 +1,19 @@ +class CreateMenuItems < ActiveRecord::Migration[5.0] + def change + create_table :menu_items do |t| + t.string :item_code, :null => false + t.string :name, :null => false + t.string :alt_name + t.string :type, :null => false, :default => "SimpleMenuItem" + t.references :menu_category, foreign_key: true + t.references :menu_item, foreign_key: true + t.integer :min_selectable_item, :null => false, :default => 1 + t.integer :max_selectable_item, :null => false, :default => 1 + t.json :options #save value + t.json :attributes #value IDS + t.string :created_by + + t.timestamps + end + end +end diff --git a/db/migrate/20170402083337_create_menu_item_attributes.rb b/db/migrate/20170402083337_create_menu_item_attributes.rb new file mode 100644 index 00000000..b2c3b0fd --- /dev/null +++ b/db/migrate/20170402083337_create_menu_item_attributes.rb @@ -0,0 +1,11 @@ +class CreateMenuItemAttributes < ActiveRecord::Migration[5.0] + def change + create_table :menu_item_attributes do |t| + t.string :attribute_type, :null => false + t.string :name, :null => false + t.string :value, :null => false + + t.timestamps + end + end +end diff --git a/db/migrate/20170402083525_create_menu_item_options.rb b/db/migrate/20170402083525_create_menu_item_options.rb new file mode 100644 index 00000000..a9e9734a --- /dev/null +++ b/db/migrate/20170402083525_create_menu_item_options.rb @@ -0,0 +1,10 @@ +class CreateMenuItemOptions < ActiveRecord::Migration[5.0] + def change + create_table :menu_item_options do |t| + t.string :name, :null => false + t.string :value, :null => false + + t.timestamps + end + end +end diff --git a/db/migrate/20170402084230_create_menu_item_instances.rb b/db/migrate/20170402084230_create_menu_item_instances.rb new file mode 100644 index 00000000..64dd1e13 --- /dev/null +++ b/db/migrate/20170402084230_create_menu_item_instances.rb @@ -0,0 +1,14 @@ +class CreateMenuItemInstances < ActiveRecord::Migration[5.0] + def change + create_table :menu_item_instances do |t| + t.references :menu_item, :foreign_key => true, :null => false + t.string :item_instance_code, :null => false + t.json :attributes + t.decimal :price, :null => false + t.boolean :is_available, :null => false, :default => true + t.boolean :is_on_promotion, :null => false, :default => false + t.decimal :promotion_price, :null => false, :default => false + t.timestamps + end + end +end diff --git a/db/migrate/20170403135121_create_customers.rb b/db/migrate/20170403135121_create_customers.rb new file mode 100644 index 00000000..75e63f7a --- /dev/null +++ b/db/migrate/20170403135121_create_customers.rb @@ -0,0 +1,15 @@ +class CreateCustomers < ActiveRecord::Migration[5.0] + def change + create_table :customers do |t| + t.string :name, :null => false + t.string :company + t.string :contact_no + t.string :email + t.string :membership_id + t.string :membership_type + t.string :membership_authentication_code + + t.timestamps + end + end +end diff --git a/db/migrate/20170403135934_create_orders.rb b/db/migrate/20170403135934_create_orders.rb new file mode 100644 index 00000000..d318386e --- /dev/null +++ b/db/migrate/20170403135934_create_orders.rb @@ -0,0 +1,17 @@ +class CreateOrders < ActiveRecord::Migration[5.0] + def change + create_table :orders do |t| + t.datetime :date, :null => false + t.string :source, :null => false, :default => "emenu" + t.string :order_type, :null => false, :default => "dine-in" + t.references :customer, foreign_key: true + t.integer :item_count, :null => false, :default => 0 + t.integer :quantity_count, :null => false, :default => 0 + t.string :status, :null => false, :default => "new" + t.json :waiters + t.json :guest_info + + t.timestamps + end + end +end diff --git a/db/migrate/20170403140820_create_order_items.rb b/db/migrate/20170403140820_create_order_items.rb new file mode 100644 index 00000000..537178d0 --- /dev/null +++ b/db/migrate/20170403140820_create_order_items.rb @@ -0,0 +1,18 @@ +class CreateOrderItems < ActiveRecord::Migration[5.0] + def change + create_table :order_items do |t| + t.references :order, foreign_key: true, :null => false + t.string :order_item_status, :null => false, :default => "new" + t.string :item_code, :null => false + t.string :item_name, :null => false + t.integer :qty, :null => false + t.string :item_order_by #person who order this + t.string :remark + t.string :options + t.string :variants + t.json :set_menu_items #this parameter is require to route the items correctly + + t.timestamps + end + end +end diff --git a/db/migrate/20170403142424_create_dining_facilities.rb b/db/migrate/20170403142424_create_dining_facilities.rb new file mode 100644 index 00000000..3e250a54 --- /dev/null +++ b/db/migrate/20170403142424_create_dining_facilities.rb @@ -0,0 +1,16 @@ +class CreateDiningFacilities < ActiveRecord::Migration[5.0] + def change + create_table :dining_facilities do |t| + t.references :zone, foreign_key: true + t.string :name, :null => false + t.string :type, :null => false, :default => "table" + t.integer :seater, :null => false, :default => 2 + t.integer :order_by + + t.string :created_by + t.boolean :is_active, :null => false, :default => true + + t.timestamps + end + end +end diff --git a/db/migrate/20170403143526_create_dining_ins.rb b/db/migrate/20170403143526_create_dining_ins.rb new file mode 100644 index 00000000..546e74b0 --- /dev/null +++ b/db/migrate/20170403143526_create_dining_ins.rb @@ -0,0 +1,11 @@ +class CreateDiningIns < ActiveRecord::Migration[5.0] + def change + create_table :dining_ins do |t| + t.references :table + t.references :order + t.boolean :currently_occupied, :default => false #there will only be 1 true - where table_id+order_id + + t.timestamps + end + end +end diff --git a/db/migrate/20170403144732_create_room_bookings.rb b/db/migrate/20170403144732_create_room_bookings.rb new file mode 100644 index 00000000..16f17875 --- /dev/null +++ b/db/migrate/20170403144732_create_room_bookings.rb @@ -0,0 +1,15 @@ +class CreateRoomBookings < ActiveRecord::Migration[5.0] + def change + create_table :room_bookings do |t| + t.references :room, :null => false + t.datetime :checkin_at + t.datetime :checkout_at + t.string :checkout_by + t.datetime :reserved_at + t.string :reserved_by + t.string :status, :null => false, :default => "new" + t.boolean :is_currently_checkin, :default => false, :null => true + t.timestamps + end + end +end diff --git a/db/migrate/20170403145042_create_room_orders.rb b/db/migrate/20170403145042_create_room_orders.rb new file mode 100644 index 00000000..00f54545 --- /dev/null +++ b/db/migrate/20170403145042_create_room_orders.rb @@ -0,0 +1,11 @@ +class CreateRoomOrders < ActiveRecord::Migration[5.0] + def change + create_table :room_orders do |t| + t.references :room, foreign_key: true + t.references :orders, foreign_key: true + t.string :order_by + + t.timestamps + end + end +end diff --git a/db/schema.txt b/db/schema.txt index 88d686c1..173289b2 100644 --- a/db/schema.txt +++ b/db/schema.txt @@ -1,14 +1,53 @@ zone {name} seat_tables {table_name, seater, table_type:[square, round, ], position-x, position-y} -room {Name, seater, created_by, is_active, order_by} +room {name, seater, created_by, is_active, order_by} menu {name, is_active, valid_days, valid_time_from, valid_time_to} -menu_category {menu, name, alt_name, order_no, parent_category_id} -menu_items { menu_category, order_no, product_code, picture, menu_name, alt_menu_name, price, menu_item_type:[simple| set| DIY], available_size:[], -variants:[{product_code, name, picture, add_on_price}], allow_multiple_variants_selection: boolean, set_menu_items:[menu_items], is_sold_out, is_on_promotion -promotion_price, promotion_qty} +menu_category {menu, name, alt_name, order_by, parent_category_id} -order { id, date, order_source [tablet, order_station, emenu, api], order_type [dine-in, takeaway, delivery], item_count, quantity_count, status [new, processing, fulfilled], waiters[], guest_info: {customer_id, membership_id, }} +menu_item_attributes: {attribute_type, name, value} +menu_item_options: {option_type, name, value} + +menu_item : { + category_code : "", + item_code : "", + name : "", + alt_name : "", + type : "[SIMPLE | SET | DIY]", + attributes : [], + parent_items : [], + child_items : [], + min_selectable_item : 0, + max_selectable_item : 0, + menu_item_instances : [], + options : [], +} + +menu_item_instance : { + item_instance_code : "", + menu_item_attribute_values : [], + item_code : "", + parent_item_code : "", + price : 0.00, + is_available : t/f, + is_on_promotion : t/f, + promotion_price : 0.00, +} + +order_item : { + order_item_code : "", + item_instance_code : "", + quantity : 0, + option_values : [], + sub_order_items : [], +} + +menu_items { menu_category, order_by, product_code, picture, menu_name, alt_menu_name, price, menu_item_type:[simple| set| DIY], available_size:[small: {product_code, price}, medium: {product_code, price}, large: {product_code, price}], +variants:[{product_code, name, picture, add_on_price, options {option_name, option_value} }], max_variants_selection: integer, set_menu_items:[menu_items], is_sold_out, is_on_promotion +promotion_price, options {option_name, option_value}} + + +order { id, date, order_ref, order_source [tablet, order_station, emenu, api], order_type [dine-in, takeaway, delivery],customer_id, item_count, quantity_count, status [new, processing, fulfilled], waiters[], guest_info: {adult_count, child_count, woman_count, man_count}} order_items { order_item_status, product_code, name, qty, price, remark, options , variants: [], set_menu_items :[]} order_delivery_info {name, address, contact_no, delivery-by [InHouse | YDoor2Door | Food2U], tracker-id, sale} dine-in-table {table, order, status} diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb new file mode 100644 index 00000000..3399b1f5 --- /dev/null +++ b/spec/models/customer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Customer, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/dining_facility_spec.rb b/spec/models/dining_facility_spec.rb new file mode 100644 index 00000000..8560358d --- /dev/null +++ b/spec/models/dining_facility_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DiningFacility, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/dining_in_spec.rb b/spec/models/dining_in_spec.rb new file mode 100644 index 00000000..e6429905 --- /dev/null +++ b/spec/models/dining_in_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DiningIn, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/menu_category_spec.rb b/spec/models/menu_category_spec.rb index 37f85dff..2fa72364 100644 --- a/spec/models/menu_category_spec.rb +++ b/spec/models/menu_category_spec.rb @@ -4,4 +4,19 @@ RSpec.describe MenuCategory, type: :model do it { should validate_presence_of(:name) } it { should belong_to(:menu) } + describe ' #parent & #children' do + it 'should be able to do parent tree' do + menu = Menu.new(:name => "Test Category Menu", :is_active => true ) + menu.save! + + c1 = MenuCategory.new(:name =>"Parent Category", :menu => menu) + c1.save! + c2 = MenuCategory.new(:name =>"Child Category", :menu => menu, :parent => c1) + c2.save + + expect(c1.children).to include(c2) + expect(c2.parent).to eq c1 + end + end + end diff --git a/spec/models/menu_item_attribute_spec.rb b/spec/models/menu_item_attribute_spec.rb new file mode 100644 index 00000000..8d75811b --- /dev/null +++ b/spec/models/menu_item_attribute_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe MenuItemAttribute, type: :model do + it { should validate_presence_of(:attribute_type) } + it { should validate_presence_of(:name) } + it { should validate_presence_of(:value) } +end diff --git a/spec/models/menu_item_instance_spec.rb b/spec/models/menu_item_instance_spec.rb new file mode 100644 index 00000000..ac15d04e --- /dev/null +++ b/spec/models/menu_item_instance_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe MenuItemInstance, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/menu_item_option_spec.rb b/spec/models/menu_item_option_spec.rb new file mode 100644 index 00000000..45c9271a --- /dev/null +++ b/spec/models/menu_item_option_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +RSpec.describe MenuItemOption, type: :model do + it { should validate_presence_of(:name) } + it { should validate_presence_of(:value) } +end diff --git a/spec/models/menu_item_spec.rb b/spec/models/menu_item_spec.rb new file mode 100644 index 00000000..42544dfb --- /dev/null +++ b/spec/models/menu_item_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe MenuItem, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/order_item_spec.rb b/spec/models/order_item_spec.rb new file mode 100644 index 00000000..3b424122 --- /dev/null +++ b/spec/models/order_item_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe OrderItem, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb new file mode 100644 index 00000000..f48229a0 --- /dev/null +++ b/spec/models/order_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Order, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/room_booking_spec.rb b/spec/models/room_booking_spec.rb new file mode 100644 index 00000000..7b2b3b79 --- /dev/null +++ b/spec/models/room_booking_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe RoomBooking, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/room_order_spec.rb b/spec/models/room_order_spec.rb new file mode 100644 index 00000000..f148edd8 --- /dev/null +++ b/spec/models/room_order_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe RoomOrder, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/room_spec.rb b/spec/models/room_spec.rb deleted file mode 100644 index e961db79..00000000 --- a/spec/models/room_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'rails_helper' - -RSpec.describe Room, type: :model do - it { should belong_to(:zone) } - - it { should validate_presence_of(:name) } - it { should validate_presence_of(:seater) } - it { should validate_presence_of(:is_active) } - -end diff --git a/spec/models/seat_table_spec.rb b/spec/models/seat_table_spec.rb deleted file mode 100644 index 500b4679..00000000 --- a/spec/models/seat_table_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'rails_helper' - -RSpec.describe SeatTable, type: :model do - # Association test - # ensure an item record belongs to a single todo record - it { should belong_to(:zone) } - # Validation test - # ensure column name is present before saving - it { should validate_presence_of(:name) } - it { should validate_presence_of(:order_by) } - it { should validate_presence_of(:created_by) } - -end diff --git a/spec/requests/api/restaurant/seat_tables_spec.rb b/spec/requests/api/restaurant/seat_tables_spec.rb deleted file mode 100644 index ddd0111a..00000000 --- a/spec/requests/api/restaurant/seat_tables_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'Seat Table API', type: :request do - # initialize test data - let!(:seat_table) { create_list(:seat_table, 10) } - let(:seat_table_id) { seat_tables.first.id } - - # Test suite for GET /todos - describe 'GET /api/restaurant/seat_tables' do - # make HTTP get request before each example - before { get '/api/restaurant/seat_tables' } - - it 'returns Seat Tables' do - # Note `json` is a custom helper to parse JSON responses - expect(json).not_to be_empty - expect(json.size).to eq(10) - end - - it 'returns status code 200' do - expect(response).to have_http_status(200) - end - end - - -end