Sha256: 958afa2abe6e2f41002bf8d5ff7e537b395c1960b6ab5e0865f97fdbf3859c97

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

module Mks
  module Edm
    class EquipmentLocationsController < ApplicationController
      before_action :set_equipment_location, only: [:update]

      def index
        render json: Mks::Common::MethodResponse.success_response(EquipmentLocation.all)
      end

      def create
        el = EquipmentLocation.new(equipment_location_params)
        if el.valid?
          el.save
          res = Mks::Common::MethodResponse.success_response(el, 'Equipment location saved successfully !')
          render json: res
        else
          res = Mks::Common::MethodResponse.failure_response(el)
          render json: res, status: :unprocessable_entity
        end
      end

      def update
        if @el.update(equipment_location_params)
          res = Mks::Common::MethodResponse.success_response(@el, 'Equipment location updated successfully !')
          render json: res
        else
          res = Mks::Common::MethodResponse.failure_response(@el)
          render json: res, status: :unprocessable_entity
        end
      end

      def service_providers
        data = EquipmentLocation.joins(:location_type)
                                             .where('mks_edm_location_types.name = ?', 'Service Provider')
        render json: Mks::Common::MethodResponse.success_response(data)
      end

      def stores
        data = EquipmentLocation.joins(:location_type)
                                  .where('mks_edm_location_types.name = ?', 'Store')
        render json: Mks::Common::MethodResponse.success_response(data)
      end

      private

      def equipment_location_params
        params.require(:equipment_location).permit(:id, :code, :name, :description, :address, :location_type_id)
      end

      def set_equipment_location
        @el = EquipmentLocation.find(params[:id])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mks_edm-1.0.5 app/controllers/mks/edm/equipment_locations_controller.rb
mks_edm-1.0.4 app/controllers/mks/edm/equipment_locations_controller.rb
mks_edm-1.0.2 app/controllers/mks/edm/equipment_locations_controller.rb
mks_edm-1.0.1 app/controllers/mks/edm/equipment_locations_controller.rb