Sha256: e1ad0e86c795a87720cfe19e57ae53c06ea74c939eb8d9b7fbaf64fa5ff3bf18

Contents?: true

Size: 1.89 KB

Versions: 4

Compression:

Stored size: 1.89 KB

Contents

module Mks
  module Edm
    class EquipmentTypesController < ApplicationController
      before_action :set_equipment_type, only: %i[show update destroy]

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

      def nodes
        equipment_types = EquipmentType.all
        types = equipment_types.map do |et|
          {
            data: {
              id: et.id,
              code: et.code,
              name: et.name,
              description: et.description,
              type: 'ET'
            },
            leaf: false
          }
        end
        render json: types
      end

      def show
        render json: Mks::Common::MethodResponse.success_response(@equipment_type)
      end

      def create
        @equipment_type = EquipmentType.new(equipment_type_params)

        if @equipment_type.save
          response = Mks::Common::MethodResponse.success_response(@equipment_type,
                                      'Equipment type created successfully!')
          render json: response, status: :created, location: @equipment_type
        else
          render json: Mks::Common::MethodResponse.failure_response(@equipment_type), status: :unprocessable_entity
        end
      end

      def update
        if @equipment_type.update(equipment_type_params)
          response = Mks::Common::MethodResponse.success_response(@equipment_type,
                                      'Equipment type updated successfully!')
          render json: response
        else
          render json: Mks::Common::MethodResponse.failure_response(@equipment_type), status: :unprocessable_entity
        end
      end


      private


      def set_equipment_type
        @equipment_type = EquipmentType.find(params[:id])
      end

      def equipment_type_params
        params.require(:equipment_type).permit(:code, :name, :description)
      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_types_controller.rb
mks_edm-1.0.4 app/controllers/mks/edm/equipment_types_controller.rb
mks_edm-1.0.2 app/controllers/mks/edm/equipment_types_controller.rb
mks_edm-1.0.1 app/controllers/mks/edm/equipment_types_controller.rb