Sha256: db11d01644bf2d35624497814d2fe49915ebbfbe32d295fc8ca2dfa6341c7d83

Contents?: true

Size: 1.95 KB

Versions: 9

Compression:

Stored size: 1.95 KB

Contents

module Logistics
  module Core
    class DeclarationTypesController < ApplicationController
      before_action :set_declaration_type, only: [:update]

      def index
        declaration_types = DeclarationType.includes(:transaction_type)
        data = ApplicationRecord.as_json(declaration_types)
        response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
        render json: response
      end

      def filter_by_transaction_type
        declaration_types = DeclarationType.includes(:transaction_type)
                                           .where(transaction_type_id: params[:id])
        data = ApplicationRecord.as_json(declaration_types)
        response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
        render json: response
      end

      def create
        @declaration_type = DeclarationType.new(declaration_type_params)
        if @declaration_type.save
          response = Mks::Common::MethodResponse.new(true, 'Declaration type saved successfully!', @declaration_type, nil, nil)
        else
          errors = Mks::Common::Util.error_messages @declaration_type, 'Declaration type'
          response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
        end
        render json: response
      end

      def update
        if @declaration_type.update(declaration_type_params)
          response = Mks::Common::MethodResponse.new(true, "Declaration type updated successfully!", @declaration_type, nil, nil)
        else
          errors = Mks::Common::Util.error_messages @declaration_type, "Declaration type"
          response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
        end
        render json: response
      end

      private

      def set_declaration_type
        @declaration_type = DeclarationType.find(params[:id])
      end

      def declaration_type_params
        params.require(:declaration_type).permit(:code, :name, :transaction_type_id)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/declaration_types_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/declaration_types_controller.rb