Sha256: 04c88b6fc7d8b0744d2372d688dbedaf8d98691112f92201ad017ed29849bf14

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

module Logistics
  module Core
    class DeclarantsController < ApplicationController
      before_action :set_declarant, only: [:update]

      def index
        declarants = Declarant.all
        response = Mks::Common::MethodResponse.new(true, nil, declarants, nil, nil)
        render json: response
      end

      def create
        @declarant = Declarant.new(declarant_params)
        if @declarant.save
          response = Mks::Common::MethodResponse.new(true, 'Declarant saved successfully!', @declarant, nil, nil)
        else
          errors = Mks::Common::Util.error_messages @declarant, 'Declarant'
          response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
        end
        render json: response
      end

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

      private

      def set_declarant
        @declarant = Declarant.find(params[:id])
      end

      def declarant_params
        params.require(:declarant).permit(:first_name, :last_name, :number)
      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/declarants_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/declarants_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/declarants_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/declarants_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/declarants_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/declarants_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/declarants_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/declarants_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/declarants_controller.rb