module Logistics module Core class WarehousesController < ApplicationController before_action :set_warehouse, only: [:update] def index @warehouses = Warehouse.all warehouse_array =[] @warehouses.each { |warehouse| warehouse_array.push({:id => warehouse.id, :code => warehouse.code, :name => warehouse.name, :description => warehouse.description, :location => warehouse.location, :email => warehouse.email, :contact_telephone => warehouse.contact_telephone }) } @response = Mks::Common::MethodResponse.new(true, nil, warehouse_array, nil, nil) render json: @response end def create @warehouse= Warehouse.new(warehouse_params) if @warehouse.valid? @warehouse.save @response = Mks::Common::MethodResponse.new(true, 'Warehouse saved successfully !',nil,nil,nil); render json: @response else errors = Mks::Common::Util.error_messages @warehouse, 'Warehouse' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end def update if @warehouse.update_attributes(warehouse_params) @warehouse.save @response = Mks::Common::MethodResponse.new(true, 'Warehouse updated successfully !', nil, nil, nil) render json: @response else errors = Mks::Common::Util.error_messages @warehouse, 'Warehouse' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end def get_requests_without_storage_data offer_request_array = [] offer_requests = OfferRequest.where('warehouse_id' => nil, 'days_until_loaded'=>nil, 'status' => 'approved') offer_requests.each do |off_req| offer_request_array.push({:id => off_req.id, :request_no => off_req.request_no, :client_id => off_req.client_id, :client => off_req.client.name}) end response = Mks::Common::MethodResponse.new(true, nil, offer_request_array, nil, nil) render json: response end private # Use callbacks to share common setup or constraints between actions. def set_warehouse @warehouse = Warehouse.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def warehouse_params params.require(:warehouse).permit(:code, :name, :description, :location, :email, :contact_telephone) end end end end