Ejemplo n.º 1
0
def handler(event, context):
    amount = json.loads(event['body'])
    new_balance = DBHelper.update_balance(amount["amount"], credit=True)
    transaction = DBHelper.deposit(credit=amount["amount"],
                                   balance=new_balance)
    print("Transaction: {0}".format(transaction))
    return {"statusCode": 200, "body": json.dumps(transaction)}
Ejemplo n.º 2
0
    def post(self):
        amount = Deposit.parser.parse_args()
        new_balance = DBHelper.update_balance(amount["amount"], credit=True)
        transaction = DBHelper.deposit(credit=amount["amount"],
                                       balance=new_balance)

        return transaction
Ejemplo n.º 3
0
    def post(self):
        amount = Withdraw.parser.parse_args()
        new_balance = DBHelper.update_balance(amount["amount"], credit=False)

        if not new_balance:
            return {
                'error': 'Cannot perform withdrawal. Balance would be below 0.'
            }, 403
        else:
            transaction = DBHelper.withdraw(debit=amount["amount"],
                                            balance=new_balance)
            return transaction
Ejemplo n.º 4
0
def handler(event, context):
    print("Event: {0}".format(json.loads(event['body'])))
    amount = json.loads(event['body'])
    new_balance = DBHelper.update_balance(amount["amount"], credit=False)

    if not new_balance:
        return {
            "statusCode":
            403,
            "body":
            json.dumps({
                'error':
                'Cannot perform withdrawal. Balance would be below 0.'
            })
        }
    else:
        transaction = DBHelper.withdraw(debit=amount["amount"],
                                        balance=new_balance)
        return {"statusCode": 200, "body": json.dumps(transaction)}
Ejemplo n.º 5
0
def handler(event, context):
    return {"statusCode": 200, "body": json.dumps(DBHelper.get_transactions())}
Ejemplo n.º 6
0
 def get(self):
     return {'balance': DBHelper.get_balance()}
Ejemplo n.º 7
0
 def get(self):
     return DBHelper.get_transactions()
Ejemplo n.º 8
0
def handler(event, context):
    return {
        "statusCode": 200,
        "body": json.dumps({'balance': DBHelper.get_balance()})
    }