Esempio n. 1
0
def send_funds(wallet_id):
    transaction_data = FundsToSend().load(request.json)

    from_wallet = db_utils.get_entry_by_uid(Wallets, wallet_id)
    assert from_wallet.funds > transaction_data["amount"], "Not enough funds"
    db_utils.update_entry(
        from_wallet,
        funds=Wallets.funds - transaction_data["amount"],
        commit=False,
    )

    to_wallet = db_utils.get_entry_by_uid(Wallets,
                                          transaction_data["to_wallet"])
    db_utils.update_entry(
        to_wallet,
        funds=Wallets.funds + transaction_data["amount"],
        commit=False,
    )

    transaction = db_utils.create_entry(
        Transactions,
        from_wallet_uid=wallet_id,
        to_wallet_uid=transaction_data["to_wallet"],
        amount=transaction_data["amount"],
    )
    return jsonify(TransactionData().dump(transaction))
Esempio n. 2
0
def update_wallet(wallet_id):
    wallet_data = WalletToUpdate().load(request.json)
    wallet = db_utils.get_entry_by_uid(Wallets, wallet_id)
    db_utils.update_entry(wallet, **wallet_data)
    return jsonify(StatusResponse().dump({"code": 200}))
Esempio n. 3
0
def get_wallet_by_id(wallet_id):
    wallet = db_utils.get_entry_by_uid(Wallets, wallet_id)
    return jsonify(WalletData().dump(wallet))
Esempio n. 4
0
def update_user(user_id):
    user_data = UserToUpdate().load(request.json)
    user = db_utils.get_entry_by_uid(Users, user_id)
    db_utils.update_entry(user, **user_data)
    return jsonify(StatusResponse().dump({"code": 200}))
Esempio n. 5
0
def get_user_by_id(user_id):
    user = db_utils.get_entry_by_uid(Users, user_id)
    return jsonify(UserData().dump(user))