38 lines
874 B
Ruby
Executable File
38 lines
874 B
Ruby
Executable File
class Api::CustomersController < ActionController::API
|
|
|
|
#List all active customers by name
|
|
def index
|
|
@customers = Customer.order("name asc")
|
|
end
|
|
|
|
#Show customer by ID
|
|
def show
|
|
@customer = Customer.find_by(params[:id])
|
|
end
|
|
|
|
def create
|
|
return unless params[:name].present? && params[:email].present? && params[:contact_no].present?
|
|
@customer = Customer.new(name: params[:name], email: params[:email], contact_no: params[:contact_no])
|
|
if @customer.save
|
|
status = true
|
|
else
|
|
status = false
|
|
end
|
|
render json: status
|
|
end
|
|
|
|
def get_customer_by_phone
|
|
if @customer = Customer.find_by_contact_no(params[:contact_no])
|
|
status = true
|
|
else
|
|
status = false
|
|
end
|
|
render json: status
|
|
end
|
|
|
|
#Show customer detail by Order item
|
|
def get_customer_order
|
|
@customer = Customer.find(params[:id])
|
|
end
|
|
end
|