async def get(self, request, contract_id): """Get all payments from database for current contract""" payments = await get_all_payments_for_current_contract(contract_id) producer.send( 'sanic', b'Operation: Get all payments for current contract. Success: True') return response.json(payments)
async def post(self, request): """Add new contract to database""" data, err = ContractSchema().load(request.json) if err: raise ValidationError('ValidationError') contract_id = await post_new_contract(data) contract = await get_contract_by_id(contract_id) producer.send('sanic', b'Operation: Add new contract. Success: True') return response.json(contract)
async def put(self, request, contract_id): """Change contract by id in database""" data, err = ContractSchema().load(request.json) if err: raise ValidationError('ValidationError') contract = await put_contract_by_id(data, contract_id) producer.send('sanic', b'Operation: Change contract by id. Success: True') return response.json(contract)
async def post(self, request, contract_id): """Add new payment to database""" data, err = PaymentSchema().load(request.json) if err: raise ValidationError('ValidationError') data['contracts_id'] = contract_id payment_id = await post_new_payment(data) payment = await get_payment_by_id(contract_id, payment_id) producer.send('sanic', b'Operation: Add new payment. Success: True') return response.json(payment)
async def get(self, request): """Get all contracts from database""" contracts = await get_all_contracts() producer.send('sanic', b'Operation: Get all contracts. Success: True') return response.json(contracts)
async def delete(self, request, contract_id): """Delete contract by id from database""" contract = await delete_contract_by_id(contract_id) producer.send('sanic', b'Operation: Delete contract by id. Success: True') return response.json(contract)
async def get(self, request, contract_id): """Get contract by id from database""" contract = await get_contract_by_id(contract_id) producer.send('sanic', b'Operation: Get contract by id. Success: True') return response.json(contract)
async def delete(self, request, contract_id, payment_id): """Delete payment by id in database""" payment = await delete_payment_by_id(contract_id, payment_id) producer.send('sanic', b'Operation: Delete payment by id. Success: True') return response.json(payment)