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