module Logistics module Core class EslTransportTariffRatesController < ApplicationController before_action :set_esl_transport_tariff_rate, only: [:update] def index esl_transport_tariff_rates = EslTransportTariffRate.all data = ActiveModelSerializers::SerializableResource.new(esl_transport_tariff_rates).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def filter_by_tariff esl_transport_tariff_rates = EslTransportTariffRate.where(:esl_transport_tariff_id => params[:id]) data = ActiveModelSerializers::SerializableResource.new(esl_transport_tariff_rates).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def create @esl_transport_tariff_rate = EslTransportTariffRate.new(esl_transport_tariff_rate_params) if @esl_transport_tariff_rate.save response = Mks::Common::MethodResponse.new(true, 'ESL transport tariff rate saved successfully!', @esl_transport_tariff_rate, nil, nil) else errors = Mks::Common::Util.error_messages @esl_transport_tariff_rate, 'ESL transport tariff rate' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end def update if @esl_transport_tariff_rate.update(esl_transport_tariff_rate_params) response = Mks::Common::MethodResponse.new(true, "ESL transport tariff rate updated successfully!", @esl_transport_tariff_rate, nil, nil) else errors = Mks::Common::Util.error_messages @esl_transport_tariff_rate, "ESL transport tariff rate" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end private def set_esl_transport_tariff_rate @esl_transport_tariff_rate = EslTransportTariffRate.find(params[:id]) end def esl_transport_tariff_rate_params params.require(:esl_transport_tariff_rate).permit(:esl_transport_tariff_id, :qt_from, :qt_to, :rate) end end end end