module Logistics module Core class ContractsController < ApplicationController before_action :set_contract, only: [:update] def index contracts = Contract.all data = ActiveModelSerializers::SerializableResource.new(contracts).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def get_contract_by_client contracts = Contract.where(client_id: params[:client_id]) data = ActiveModelSerializers::SerializableResource.new(contracts).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def create contract = Contract.new(contract_params) if contract.valid? contract.save response = Mks::Common::MethodResponse.new(true, "Contract captured successfully !", nil, nil, nil); else errors = Mks::Util.error_messages(contract, "Contract") response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end def update if @contract.update(contract_params) @contract.save response = Mks::Common::MethodResponse.new(true, "Contract updated successfully !", nil, nil, nil) else errors = Mks::Util.error_messages(@contract, "Contract") response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end private def set_contract @contract = Contract.find(params[:id]) end def contract_params params.require(:contract).permit(:contract_number, :title, :start_date, :end_date, :contract_signed_date, :client_id) end end end end