From 40423c12d3ec90c7de8588019172ee3f96ac427b Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Mon, 27 Mar 2017 22:09:16 +0630 Subject: [PATCH] menu and menu_category --- .../api/restaurant/seat_tables_controller.rb | 5 ++++ app/models/menu.rb | 6 +++++ app/models/menu_category.rb | 5 ++++ app/models/room.rb | 6 +++++ app/models/zone.rb | 1 + config/application.rb | 2 ++ config/routes.rb | 1 + db/migrate/20170325103022_create_rooms.rb | 13 ++++++++++ db/migrate/20170325111608_create_menus.rb | 13 ++++++++++ .../20170327152733_create_menu_categories.rb | 13 ++++++++++ db/schema.txt | 10 ++++---- spec/factories/rooms.rb | 11 ++++++++ spec/factories/seat_tables.rb | 11 +++++--- spec/models/menu_category_spec.rb | 7 ++++++ spec/models/menu_spec.rb | 12 +++++++++ spec/models/room_spec.rb | 10 ++++++++ spec/models/zone_spec.rb | 2 ++ .../api/restaurant/seat_tables_spec.rb | 25 +++++++++++++++++++ 18 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 app/controllers/api/restaurant/seat_tables_controller.rb create mode 100644 app/models/menu.rb create mode 100644 app/models/menu_category.rb create mode 100644 app/models/room.rb create mode 100644 db/migrate/20170325103022_create_rooms.rb create mode 100644 db/migrate/20170325111608_create_menus.rb create mode 100644 db/migrate/20170327152733_create_menu_categories.rb create mode 100644 spec/factories/rooms.rb create mode 100644 spec/models/menu_category_spec.rb create mode 100644 spec/models/menu_spec.rb create mode 100644 spec/models/room_spec.rb diff --git a/app/controllers/api/restaurant/seat_tables_controller.rb b/app/controllers/api/restaurant/seat_tables_controller.rb new file mode 100644 index 00000000..4b470b68 --- /dev/null +++ b/app/controllers/api/restaurant/seat_tables_controller.rb @@ -0,0 +1,5 @@ +class Api::Restaurant::SeatTablesController < ActionController::API + def index + render json: SeatTable.order("order_by") + end +end diff --git a/app/models/menu.rb b/app/models/menu.rb new file mode 100644 index 00000000..e2933314 --- /dev/null +++ b/app/models/menu.rb @@ -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 diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb new file mode 100644 index 00000000..8ef15958 --- /dev/null +++ b/app/models/menu_category.rb @@ -0,0 +1,5 @@ +class MenuCategory < ApplicationRecord + belongs_to :menu + + validates_presence_of :name +end diff --git a/app/models/room.rb b/app/models/room.rb new file mode 100644 index 00000000..7bef4c5f --- /dev/null +++ b/app/models/room.rb @@ -0,0 +1,6 @@ +class Room < ApplicationRecord + belongs_to :zone + + validates_presence_of :name,:seater, :order_by, :created_by, :is_active + +end diff --git a/app/models/zone.rb b/app/models/zone.rb index 6ce3dd0a..05ab62f2 100644 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 3127c1ca..37494d3d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 2d2fadbd..177afb55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20170325103022_create_rooms.rb b/db/migrate/20170325103022_create_rooms.rb new file mode 100644 index 00000000..2f153f32 --- /dev/null +++ b/db/migrate/20170325103022_create_rooms.rb @@ -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 diff --git a/db/migrate/20170325111608_create_menus.rb b/db/migrate/20170325111608_create_menus.rb new file mode 100644 index 00000000..50752f07 --- /dev/null +++ b/db/migrate/20170325111608_create_menus.rb @@ -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 diff --git a/db/migrate/20170327152733_create_menu_categories.rb b/db/migrate/20170327152733_create_menu_categories.rb new file mode 100644 index 00000000..a6dc0ad6 --- /dev/null +++ b/db/migrate/20170327152733_create_menu_categories.rb @@ -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 diff --git a/db/schema.txt b/db/schema.txt index 9f257d9d..88d686c1 100644 --- a/db/schema.txt +++ b/db/schema.txt @@ -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} diff --git a/spec/factories/rooms.rb b/spec/factories/rooms.rb new file mode 100644 index 00000000..ea8dd7a5 --- /dev/null +++ b/spec/factories/rooms.rb @@ -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 diff --git a/spec/factories/seat_tables.rb b/spec/factories/seat_tables.rb index 5f2fdea2..d17b0897 100644 --- a/spec/factories/seat_tables.rb +++ b/spec/factories/seat_tables.rb @@ -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 diff --git a/spec/models/menu_category_spec.rb b/spec/models/menu_category_spec.rb new file mode 100644 index 00000000..37f85dff --- /dev/null +++ b/spec/models/menu_category_spec.rb @@ -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 diff --git a/spec/models/menu_spec.rb b/spec/models/menu_spec.rb new file mode 100644 index 00000000..7a26456e --- /dev/null +++ b/spec/models/menu_spec.rb @@ -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 diff --git a/spec/models/room_spec.rb b/spec/models/room_spec.rb new file mode 100644 index 00000000..e961db79 --- /dev/null +++ b/spec/models/room_spec.rb @@ -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 diff --git a/spec/models/zone_spec.rb b/spec/models/zone_spec.rb index 7ec51333..971c3366 100644 --- a/spec/models/zone_spec.rb +++ b/spec/models/zone_spec.rb @@ -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) } diff --git a/spec/requests/api/restaurant/seat_tables_spec.rb b/spec/requests/api/restaurant/seat_tables_spec.rb index e69de29b..ddd0111a 100644 --- a/spec/requests/api/restaurant/seat_tables_spec.rb +++ b/spec/requests/api/restaurant/seat_tables_spec.rb @@ -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