Class: Logistics::Core::ContractsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/contracts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/logistics/core/contracts_controller.rb', line 20

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

#get_contract_by_clientObject



13
14
15
16
17
18
# File 'app/controllers/logistics/core/contracts_controller.rb', line 13

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

#indexObject



6
7
8
9
10
11
# File 'app/controllers/logistics/core/contracts_controller.rb', line 6

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

#updateObject



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/logistics/core/contracts_controller.rb', line 32

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