Class: MandateClaw::Api::V1::ContractsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/mandate_claw/api/v1/contracts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /mandate_claw/api/v1/contracts Body: { contract_digest, template_name, scope_type, scope_id,

parties_json, signatures_json, rendered_markdown, expires_at }


12
13
14
15
16
17
# File 'app/controllers/mandate_claw/api/v1/contracts_controller.rb', line 12

def create
  contract = SignedContract.create!(contract_params)
  render json: serialize(contract), status: :created
rescue ActiveRecord::RecordInvalid => e
  render json: { error: e.message }, status: :unprocessable_entity
end

#revokeObject

POST /mandate_claw/api/v1/contracts/:id/revoke



37
38
39
40
# File 'app/controllers/mandate_claw/api/v1/contracts_controller.rb', line 37

def revoke
  @contract.revoke!(reason: params[:reason])
  render json: { revoked: true, contract_id: @contract.id }
end

#showObject

GET /mandate_claw/api/v1/contracts/:id



20
21
22
# File 'app/controllers/mandate_claw/api/v1/contracts_controller.rb', line 20

def show
  render json: serialize(@contract)
end

#verifyObject

POST /mandate_claw/api/v1/contracts/:id/verify Returns whether the contract is active and not expired.



26
27
28
29
30
31
32
33
34
# File 'app/controllers/mandate_claw/api/v1/contracts_controller.rb', line 26

def verify
  render json: {
    contract_id: @contract.id,
    digest:      @contract.contract_digest,
    valid:       @contract.active? && !@contract.expired?,
    status:      @contract.status,
    expires_at:  @contract.expires_at
  }
end