module Logistics module Core class CustomsTransportTariffsController < ApplicationController before_action :set_customs_transport_tariff, only: [:update] def index customs_transport_tariffs = CustomsTransportTariff.all data = ActiveModelSerializers::SerializableResource.new(customs_transport_tariffs).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def create @customs_transport_tariff = CustomsTransportTariff.new(customs_transport_tariff_params) if @customs_transport_tariff.save response = Mks::Common::MethodResponse.new(true, 'Customs transport tariff saved successfully!', @customs_transport_tariff, nil, nil) else errors = Mks::Common::Util.error_messages @customs_transport_tariff, 'Customs transport tariff' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end def update if @customs_transport_tariff.update(customs_transport_tariff_params) response = Mks::Common::MethodResponse.new(true, "Customs transport tariff updated successfully!", @customs_transport_tariff, nil, nil) else errors = Mks::Common::Util.error_messages @customs_transport_tariff, "Customs transport tariff" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end private def set_customs_transport_tariff @customs_transport_tariff = CustomsTransportTariff.find(params[:id]) end def customs_transport_tariff_params params.require(:customs_transport_tariff).permit(:route_id, :entry_point_id, :total_distance, :distance_to_entry_point, :proportion) end end end end