api integrated

This commit is contained in:
Min Zeya Phyo
2017-04-19 19:39:58 +06:30
parent c4e76c53b2
commit 0a97947259
25 changed files with 755 additions and 2 deletions

View File

@@ -1,8 +1,17 @@
class Api::BookingsController < ActionController::API
class Api::BookingsController < Api::ApiController
#Show customer by ID
def create
def index
@customer = Customer.find_by(params[:id])
end
def show
@booking = Booking.find(params[:id])
end
# private
# def Bookings_params
# params.permit(:id, :order_id)
# end
end

View File

@@ -0,0 +1,33 @@
module LoginVerification
extend ActiveSupport::Concern
included do
before_action :authenticate
end
protected
# Authenticate the user with token based authentication
def authenticate
authenticate_session_token || render_unauthorized
end
def authenticate_session_token
token = session[:session_token]
if (token)
#@current_user = User.find_by(api_key: token)
Rails.logger.debug "token - " + token.to_s
@user = Employee.authenticate_by_token(token)
if @user
return true
#Maybe log - login?
end
end
end
def render_unauthorized()
redirect_to root_path
end
end

View File

@@ -0,0 +1,78 @@
class Settings::MenuItemsController < ApplicationController
before_action :set_settings_menu_item, only: [:show, :edit, :update, :destroy]
before_action :set_settings_menu_category, only: [:index, :show, :edit, :new]
# GET /settings/menu_items
# GET /settings/menu_items.json
def index
@settings_menu_items = @category.menu_items
end
# GET /settings/menu_items/1
# GET /settings/menu_items/1.json
def show
end
# GET /settings/menu_items/new
def new
@settings_menu_item = MenuItem.new
end
# GET /settings/menu_items/1/edit
def edit
end
# POST /settings/menu_items
# POST /settings/menu_items.json
def create
@settings_menu_item = MenuItem.new(settings_menu_item_params)
respond_to do |format|
if @settings_menu_item.save
format.html { redirect_to @settings_menu_item, notice: 'Menu item was successfully created.' }
format.json { render :show, status: :created, location: @settings_menu_item }
else
format.html { render :new }
format.json { render json: @settings_menu_item.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /settings/menu_items/1
# PATCH/PUT /settings/menu_items/1.json
def update
respond_to do |format|
if @settings_menu_item.update(settings_menu_item_params)
format.html { redirect_to @settings_menu_item, notice: 'Menu item was successfully updated.' }
format.json { render :show, status: :ok, location: @settings_menu_item }
else
format.html { render :edit }
format.json { render json: @settings_menu_item.errors, status: :unprocessable_entity }
end
end
end
# DELETE /settings/menu_items/1
# DELETE /settings/menu_items/1.json
def destroy
@settings_menu_item.destroy
respond_to do |format|
format.html { redirect_to settings_menu_items_url, notice: 'Menu item was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_settings_menu_item
@settings_menu_item = MenuItem.find(params[:id])
end
def set_settings_menu_category
@category = MenuCategory.find(params[:menu_category_id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def settings_menu_item_params
params.require(:settings_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by)
end
end

View File

@@ -0,0 +1,2 @@
module Settings::MenuItemsHelper
end

16
app/models/login_form.rb Normal file
View File

@@ -0,0 +1,16 @@
class LoginForm
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :emp_id, :password
validates_presence_of :emp_id, :password
def persisted?
false
end
def initialize(attributes={})
super
end
end

View File

@@ -0,0 +1,7 @@
if @status == true
#show invoice number and stuff
json.status @status
else
json.status @status
json.error_message @error_message
end

View File

@@ -0,0 +1,37 @@
if (@booking)
json.id @booking.id
json.status @booking.booking_status
json.checkin_at @booking.checkin_at
if @booking.type == "TableBooking"
json.table_id @booking.dining_facility_id
else
json.room_id @booking.dining_facility_id
end
@total_amount = 0.00
@total_tax = 0.00
if @booking.booking_orders
@booking.booking_orders.each do |bo|
order = Order.find(bo.order_id)
if (order.status == "new")
order_items = order.order_items
json.order_items order_items do |item|
json.item_instance_code item.item_code
json.item_name item.item_name
json.price item.price
json.qty item.qty
json.options item.options
json.remark item.remark
json.item_status item.order_item_status
@total_amount = @total_amount + (item.price * item.qty)
end
end
end
end
json.sub_total @total_amount
json.commerical_tax @total_amount * 0.05
json.total @total_amount + (@total_amount * 0.05)
end

View File

@@ -0,0 +1,8 @@
<div class="row">
<div class="col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3">
<%= current_login_employee.name %>
<%= current_login_employee.role %>
</div>
</div>

View File

@@ -0,0 +1,20 @@
<%= simple_form_for([:settings,@category, @settings_menu_item]) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :item_code %>
<%= f.input :name %>
<%= f.input :alt_name %>
<%= f.input :type %>
<%= f.association :menu_category %>
<%= f.association :menu_item %>
<%= f.input :min_qty %>
<%= f.input :min_selectable_item %>
<%= f.input :max_selectable_item %>
<%= f.input :created_by %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>

View File

@@ -0,0 +1,2 @@
json.extract! settings_menu_item, :id, :item_code, :name, :alt_name, :type, :menu_category_id, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by, :created_at, :updated_at
json.url settings_menu_item_url(settings_menu_item, format: :json)

View File

@@ -0,0 +1,6 @@
<h1>Editing Settings Menu Item</h1>
<%= render 'form', settings_menu_item: @settings_menu_item %>
<%= link_to 'Show', @settings_menu_item %> |
<%= link_to 'Back', settings_menu_items_path %>

View File

@@ -0,0 +1,80 @@
<div class="page-header">
<ul class="breadcrumb">
<li><a href="<%= %>">Home</a></li>
<li>Settings</li>
<li>Menu Items</li>
<span style="float: right">
<%= link_to t('.new', :default => t("helpers.links.new")),new_settings_menu_category_menu_item_path(@category),:class => 'btn btn-primary btn-sm' %>
</span>
</ul>
</div>
<div class="card">
<div class="card-block">
<h4 class="card-title">Menu Category</h4>
<table class="table">
<thead>
<tr>
<th>Menu</th>
<th>Name</th>
<th>Alt name</th>
<th>Order by</th>
<th>Parent</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<tr>
<td><%= @category.menu.name %></td>
<td><%= @category.name %></td>
<td><%= @category.alt_name %></td>
<td><%= @category.order_by %></td>
<td><%= @category.parent.name rescue "-" %></td>
<td><%= link_to 'Edit', edit_settings_menu_category_path(@category) %></td>
</tr>
</tbody>
</table>
</div>
</div>
<br/>
<div class="card">
<div class="card-block">
<h4 class="card-title">Menu Items</h4>
<table class="table">
<thead>
<tr>
<th>Item code</th>
<th>Name</th>
<th>Alt name</th>
<th>Type</th>
<th>Parent Item</th>
<th>Created by</th>
<th>Created at</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @settings_menu_items.each do |settings_menu_item| %>
<tr>
<td><%= settings_menu_item.item_code %></td>
<td><%= settings_menu_item.name %></td>
<td><%= settings_menu_item.alt_name %></td>
<td><%= settings_menu_item.type %></td>
<td><%= settings_menu_item.parent.name rescue "-" %></td>
<td><%= settings_menu_item.created_by %></td>
<td><%=l settings_menu_item.created_at, :format => :short %></td>
<td><%= link_to 'Show', settings_menu_category_menu_item_path(@category, settings_menu_item ) %></td>
<td><%= link_to 'Edit', edit_settings_menu_category_menu_item_path(@category, settings_menu_item) %></td>
<td><%= link_to 'Destroy', settings_menu_category_menu_item_path(@category, settings_menu_item ), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1 @@
json.array! @settings_menu_items, partial: 'settings_menu_items/settings_menu_item', as: :settings_menu_item

View File

@@ -0,0 +1,5 @@
<h1>New Settings Menu Item</h1>
<%= render 'form', settings_menu_item: @settings_menu_item %>
<%= link_to 'Back', settings_menu_items_path %>

View File

@@ -0,0 +1,54 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Item code:</strong>
<%= @settings_menu_item.item_code %>
</p>
<p>
<strong>Name:</strong>
<%= @settings_menu_item.name %>
</p>
<p>
<strong>Alt name:</strong>
<%= @settings_menu_item.alt_name %>
</p>
<p>
<strong>Type:</strong>
<%= @settings_menu_item.type %>
</p>
<p>
<strong>Menu category:</strong>
<%= @settings_menu_item.menu_category %>
</p>
<p>
<strong>Menu item:</strong>
<%= @settings_menu_item.menu_item %>
</p>
<p>
<strong>Min qty:</strong>
<%= @settings_menu_item.min_qty %>
</p>
<p>
<strong>Min selectable item:</strong>
<%= @settings_menu_item.min_selectable_item %>
</p>
<p>
<strong>Max selectable item:</strong>
<%= @settings_menu_item.max_selectable_item %>
</p>
<p>
<strong>Created by:</strong>
<%= @settings_menu_item.created_by %>
</p>
<%= link_to 'Edit', edit_settings_menu_item_path(@settings_menu_item) %> |
<%= link_to 'Back', settings_menu_items_path %>

View File

@@ -0,0 +1 @@
json.partial! "settings_menu_items/settings_menu_item", settings_menu_item: @settings_menu_item

View File

@@ -0,0 +1,3 @@
namespace :menu_import do
end

View File

@@ -0,0 +1,159 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe Settings::MenuItemsController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# Settings::MenuItem. As you add validations to Settings::MenuItem, be sure to
# adjust the attributes here as well.
let(:valid_attributes) {
skip("Add a hash of attributes valid for your model")
}
let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
}
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# Settings::MenuItemsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "assigns all settings_menu_items as @settings_menu_items" do
menu_item = Settings::MenuItem.create! valid_attributes
get :index, params: {}, session: valid_session
expect(assigns(:settings_menu_items)).to eq([menu_item])
end
end
describe "GET #show" do
it "assigns the requested settings_menu_item as @settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
get :show, params: {id: menu_item.to_param}, session: valid_session
expect(assigns(:settings_menu_item)).to eq(menu_item)
end
end
describe "GET #new" do
it "assigns a new settings_menu_item as @settings_menu_item" do
get :new, params: {}, session: valid_session
expect(assigns(:settings_menu_item)).to be_a_new(Settings::MenuItem)
end
end
describe "GET #edit" do
it "assigns the requested settings_menu_item as @settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
get :edit, params: {id: menu_item.to_param}, session: valid_session
expect(assigns(:settings_menu_item)).to eq(menu_item)
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new Settings::MenuItem" do
expect {
post :create, params: {settings_menu_item: valid_attributes}, session: valid_session
}.to change(Settings::MenuItem, :count).by(1)
end
it "assigns a newly created settings_menu_item as @settings_menu_item" do
post :create, params: {settings_menu_item: valid_attributes}, session: valid_session
expect(assigns(:settings_menu_item)).to be_a(Settings::MenuItem)
expect(assigns(:settings_menu_item)).to be_persisted
end
it "redirects to the created settings_menu_item" do
post :create, params: {settings_menu_item: valid_attributes}, session: valid_session
expect(response).to redirect_to(Settings::MenuItem.last)
end
end
context "with invalid params" do
it "assigns a newly created but unsaved settings_menu_item as @settings_menu_item" do
post :create, params: {settings_menu_item: invalid_attributes}, session: valid_session
expect(assigns(:settings_menu_item)).to be_a_new(Settings::MenuItem)
end
it "re-renders the 'new' template" do
post :create, params: {settings_menu_item: invalid_attributes}, session: valid_session
expect(response).to render_template("new")
end
end
end
describe "PUT #update" do
context "with valid params" do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
}
it "updates the requested settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
put :update, params: {id: menu_item.to_param, settings_menu_item: new_attributes}, session: valid_session
menu_item.reload
skip("Add assertions for updated state")
end
it "assigns the requested settings_menu_item as @settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
put :update, params: {id: menu_item.to_param, settings_menu_item: valid_attributes}, session: valid_session
expect(assigns(:settings_menu_item)).to eq(menu_item)
end
it "redirects to the settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
put :update, params: {id: menu_item.to_param, settings_menu_item: valid_attributes}, session: valid_session
expect(response).to redirect_to(menu_item)
end
end
context "with invalid params" do
it "assigns the settings_menu_item as @settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
put :update, params: {id: menu_item.to_param, settings_menu_item: invalid_attributes}, session: valid_session
expect(assigns(:settings_menu_item)).to eq(menu_item)
end
it "re-renders the 'edit' template" do
menu_item = Settings::MenuItem.create! valid_attributes
put :update, params: {id: menu_item.to_param, settings_menu_item: invalid_attributes}, session: valid_session
expect(response).to render_template("edit")
end
end
end
describe "DELETE #destroy" do
it "destroys the requested settings_menu_item" do
menu_item = Settings::MenuItem.create! valid_attributes
expect {
delete :destroy, params: {id: menu_item.to_param}, session: valid_session
}.to change(Settings::MenuItem, :count).by(-1)
end
it "redirects to the settings_menu_items list" do
menu_item = Settings::MenuItem.create! valid_attributes
delete :destroy, params: {id: menu_item.to_param}, session: valid_session
expect(response).to redirect_to(settings_menu_items_url)
end
end
end

View File

@@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Settings::MenuItemsHelper. For example:
#
# describe Settings::MenuItemsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Settings::MenuItemsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,10 @@
require 'rails_helper'
RSpec.describe "Settings::MenuItems", type: :request do
describe "GET /settings_menu_items" do
it "works! (now write some real specs)" do
get settings_menu_items_path
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,39 @@
require "rails_helper"
RSpec.describe Settings::MenuItemsController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/settings/menu_items").to route_to("settings/menu_items#index")
end
it "routes to #new" do
expect(:get => "/settings/menu_items/new").to route_to("settings/menu_items#new")
end
it "routes to #show" do
expect(:get => "/settings/menu_items/1").to route_to("settings/menu_items#show", :id => "1")
end
it "routes to #edit" do
expect(:get => "/settings/menu_items/1/edit").to route_to("settings/menu_items#edit", :id => "1")
end
it "routes to #create" do
expect(:post => "/settings/menu_items").to route_to("settings/menu_items#create")
end
it "routes to #update via PUT" do
expect(:put => "/settings/menu_items/1").to route_to("settings/menu_items#update", :id => "1")
end
it "routes to #update via PATCH" do
expect(:patch => "/settings/menu_items/1").to route_to("settings/menu_items#update", :id => "1")
end
it "routes to #destroy" do
expect(:delete => "/settings/menu_items/1").to route_to("settings/menu_items#destroy", :id => "1")
end
end
end

View File

@@ -0,0 +1,45 @@
require 'rails_helper'
RSpec.describe "settings/menu_items/edit", type: :view do
before(:each) do
@settings_menu_item = assign(:settings_menu_item, Settings::MenuItem.create!(
:item_code => "MyString",
:name => "MyString",
:alt_name => "MyString",
:type => "",
:menu_category => nil,
:menu_item => nil,
:min_qty => 1,
:min_selectable_item => 1,
:max_selectable_item => 1,
:created_by => "MyString"
))
end
it "renders the edit settings_menu_item form" do
render
assert_select "form[action=?][method=?]", settings_menu_item_path(@settings_menu_item), "post" do
assert_select "input#settings_menu_item_item_code[name=?]", "settings_menu_item[item_code]"
assert_select "input#settings_menu_item_name[name=?]", "settings_menu_item[name]"
assert_select "input#settings_menu_item_alt_name[name=?]", "settings_menu_item[alt_name]"
assert_select "input#settings_menu_item_type[name=?]", "settings_menu_item[type]"
assert_select "input#settings_menu_item_menu_category_id[name=?]", "settings_menu_item[menu_category_id]"
assert_select "input#settings_menu_item_menu_item_id[name=?]", "settings_menu_item[menu_item_id]"
assert_select "input#settings_menu_item_min_qty[name=?]", "settings_menu_item[min_qty]"
assert_select "input#settings_menu_item_min_selectable_item[name=?]", "settings_menu_item[min_selectable_item]"
assert_select "input#settings_menu_item_max_selectable_item[name=?]", "settings_menu_item[max_selectable_item]"
assert_select "input#settings_menu_item_created_by[name=?]", "settings_menu_item[created_by]"
end
end
end

View File

@@ -0,0 +1,46 @@
require 'rails_helper'
RSpec.describe "settings/menu_items/index", type: :view do
before(:each) do
assign(:settings_menu_items, [
Settings::MenuItem.create!(
:item_code => "Item Code",
:name => "Name",
:alt_name => "Alt Name",
:type => "Type",
:menu_category => nil,
:menu_item => nil,
:min_qty => 2,
:min_selectable_item => 3,
:max_selectable_item => 4,
:created_by => "Created By"
),
Settings::MenuItem.create!(
:item_code => "Item Code",
:name => "Name",
:alt_name => "Alt Name",
:type => "Type",
:menu_category => nil,
:menu_item => nil,
:min_qty => 2,
:min_selectable_item => 3,
:max_selectable_item => 4,
:created_by => "Created By"
)
])
end
it "renders a list of settings/menu_items" do
render
assert_select "tr>td", :text => "Item Code".to_s, :count => 2
assert_select "tr>td", :text => "Name".to_s, :count => 2
assert_select "tr>td", :text => "Alt Name".to_s, :count => 2
assert_select "tr>td", :text => "Type".to_s, :count => 2
assert_select "tr>td", :text => nil.to_s, :count => 2
assert_select "tr>td", :text => nil.to_s, :count => 2
assert_select "tr>td", :text => 2.to_s, :count => 2
assert_select "tr>td", :text => 3.to_s, :count => 2
assert_select "tr>td", :text => 4.to_s, :count => 2
assert_select "tr>td", :text => "Created By".to_s, :count => 2
end
end

View File

@@ -0,0 +1,45 @@
require 'rails_helper'
RSpec.describe "settings/menu_items/new", type: :view do
before(:each) do
assign(:settings_menu_item, Settings::MenuItem.new(
:item_code => "MyString",
:name => "MyString",
:alt_name => "MyString",
:type => "",
:menu_category => nil,
:menu_item => nil,
:min_qty => 1,
:min_selectable_item => 1,
:max_selectable_item => 1,
:created_by => "MyString"
))
end
it "renders new settings_menu_item form" do
render
assert_select "form[action=?][method=?]", settings_menu_items_path, "post" do
assert_select "input#settings_menu_item_item_code[name=?]", "settings_menu_item[item_code]"
assert_select "input#settings_menu_item_name[name=?]", "settings_menu_item[name]"
assert_select "input#settings_menu_item_alt_name[name=?]", "settings_menu_item[alt_name]"
assert_select "input#settings_menu_item_type[name=?]", "settings_menu_item[type]"
assert_select "input#settings_menu_item_menu_category_id[name=?]", "settings_menu_item[menu_category_id]"
assert_select "input#settings_menu_item_menu_item_id[name=?]", "settings_menu_item[menu_item_id]"
assert_select "input#settings_menu_item_min_qty[name=?]", "settings_menu_item[min_qty]"
assert_select "input#settings_menu_item_min_selectable_item[name=?]", "settings_menu_item[min_selectable_item]"
assert_select "input#settings_menu_item_max_selectable_item[name=?]", "settings_menu_item[max_selectable_item]"
assert_select "input#settings_menu_item_created_by[name=?]", "settings_menu_item[created_by]"
end
end
end

View File

@@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe "settings/menu_items/show", type: :view do
before(:each) do
@settings_menu_item = assign(:settings_menu_item, Settings::MenuItem.create!(
:item_code => "Item Code",
:name => "Name",
:alt_name => "Alt Name",
:type => "Type",
:menu_category => nil,
:menu_item => nil,
:min_qty => 2,
:min_selectable_item => 3,
:max_selectable_item => 4,
:created_by => "Created By"
))
end
it "renders attributes in <p>" do
render
expect(rendered).to match(/Item Code/)
expect(rendered).to match(/Name/)
expect(rendered).to match(/Alt Name/)
expect(rendered).to match(/Type/)
expect(rendered).to match(//)
expect(rendered).to match(//)
expect(rendered).to match(/2/)
expect(rendered).to match(/3/)
expect(rendered).to match(/4/)
expect(rendered).to match(/Created By/)
end
end