menu and menu_category
This commit is contained in:
5
app/controllers/api/restaurant/seat_tables_controller.rb
Normal file
5
app/controllers/api/restaurant/seat_tables_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Api::Restaurant::SeatTablesController < ActionController::API
|
||||
def index
|
||||
render json: SeatTable.order("order_by")
|
||||
end
|
||||
end
|
||||
6
app/models/menu.rb
Normal file
6
app/models/menu.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class Menu < ApplicationRecord
|
||||
has_many :menu_categories, dependent: :destroy
|
||||
|
||||
validates_presence_of :name,:is_active, :valid_days, :valid_time_from, :valid_time_to
|
||||
|
||||
end
|
||||
5
app/models/menu_category.rb
Normal file
5
app/models/menu_category.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class MenuCategory < ApplicationRecord
|
||||
belongs_to :menu
|
||||
|
||||
validates_presence_of :name
|
||||
end
|
||||
6
app/models/room.rb
Normal file
6
app/models/room.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class Room < ApplicationRecord
|
||||
belongs_to :zone
|
||||
|
||||
validates_presence_of :name,:seater, :order_by, :created_by, :is_active
|
||||
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
class Zone < ApplicationRecord
|
||||
# model association
|
||||
has_many :seat_tables, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
|
||||
# validations
|
||||
validates_presence_of :name, :created_by
|
||||
|
||||
@@ -11,5 +11,7 @@ module SXRestaurants
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
# Application configuration should go into files in config/initializers
|
||||
# -- all .rb files in that directory are automatically loaded.
|
||||
config.active_record.time_zone_aware_types = [:datetime, :time]
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ Rails.application.routes.draw do
|
||||
namespace :api, :defaults => { :format => 'json' } do
|
||||
namespace :restaurant do
|
||||
get 'zones' => "zones#index"
|
||||
get 'seat_tables' => "seat_tables#index"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
13
db/migrate/20170325103022_create_rooms.rb
Normal file
13
db/migrate/20170325103022_create_rooms.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
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
|
||||
13
db/migrate/20170325111608_create_menus.rb
Normal file
13
db/migrate/20170325111608_create_menus.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateMenus < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :menus do |t|
|
||||
t.string :name
|
||||
t.boolean :is_active, :null => false
|
||||
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"
|
||||
t.string :created_by
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
13
db/migrate/20170327152733_create_menu_categories.rb
Normal file
13
db/migrate/20170327152733_create_menu_categories.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateMenuCategories < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :menu_categories do |t|
|
||||
t.references :menu, foreign_key: true
|
||||
t.string :name, :null => false
|
||||
t.string :alt_name
|
||||
t.integer :order_by
|
||||
t.integer :parent_category_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,18 +1,18 @@
|
||||
zone {name}
|
||||
seat_tables {table_name, seater, table_type:[square, round, ], position-x, position-y}
|
||||
room {Name, seater,}
|
||||
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}
|
||||
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:[],
|
||||
ariants:[{product_code, name, picture, add_on_price}], allow_multiple_variants_selection: boolean, set_menu_items:[menu_items], is_sold_out, is_on_promotion
|
||||
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}
|
||||
|
||||
order { id, date, order_source [tablet, order_station, emenu, api], order_type [dine-in, takeaway, delivery], table, item_count, quantity_count, status [new, processing, fulfilled], waiters[], guest_info: {customer_id, membership_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, }}
|
||||
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}
|
||||
room-booking {room, check-in, check-out, reserved_by, status,}
|
||||
room-booking {room, check-in, check-out, reserved_by, status, orders}
|
||||
|
||||
order_queue_station {name, is_active, processing_items [product_code]}
|
||||
order_queue_printer_setting { printer_name, font_size, cut_per_item}
|
||||
|
||||
11
spec/factories/rooms.rb
Normal file
11
spec/factories/rooms.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
FactoryGirl.define do
|
||||
|
||||
factory :room do
|
||||
name { Faker::StarWars.character }
|
||||
order_by { Faker::Number.number(2)}
|
||||
seater {Faker::Number.number(2)}
|
||||
created_by {Faker::StarWars.character}
|
||||
association :zone, factory: :zone, name: "Writely"
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,11 @@
|
||||
FactoryGirl.define do
|
||||
factory :seat_tables do
|
||||
|
||||
factory :seat_table do
|
||||
name { Faker::StarWars.character }
|
||||
order_by { Faker::Number.number(5)}
|
||||
no_of_seater {Faker::Number.number(5)}
|
||||
zone_id nil
|
||||
order_by { Faker::Number.number(2)}
|
||||
no_of_seater {Faker::Number.number(2)}
|
||||
created_by {Faker::StarWars.character}
|
||||
association :zone, factory: :zone, name: "Writely"
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
7
spec/models/menu_category_spec.rb
Normal file
7
spec/models/menu_category_spec.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe MenuCategory, type: :model do
|
||||
it { should validate_presence_of(:name) }
|
||||
it { should belong_to(:menu) }
|
||||
|
||||
end
|
||||
12
spec/models/menu_spec.rb
Normal file
12
spec/models/menu_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Menu, type: :model do
|
||||
it { should have_many(:menu_categories).dependent(:destroy) }
|
||||
|
||||
it { should validate_presence_of(:name) }
|
||||
it { should validate_presence_of(:is_active) }
|
||||
it { should validate_presence_of(:valid_days) }
|
||||
it { should validate_presence_of(:valid_time_from) }
|
||||
it { should validate_presence_of(:valid_time_to) }
|
||||
|
||||
end
|
||||
10
spec/models/room_spec.rb
Normal file
10
spec/models/room_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
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
|
||||
@@ -4,6 +4,8 @@ RSpec.describe Zone, type: :model do
|
||||
# Association test
|
||||
# ensure Todo model has a 1:m relationship with the Item model
|
||||
it { should have_many(:seat_tables).dependent(:destroy) }
|
||||
it { should have_many(:rooms).dependent(:destroy) }
|
||||
|
||||
# Validation tests
|
||||
# ensure columns title and created_by are present before saving
|
||||
it { should validate_presence_of(:name) }
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user