Compare commits
1 Commits
2025-07-16
...
2025-07-14
| Author | SHA1 | Date | |
|---|---|---|---|
| 45093b0516 |
@ -24,7 +24,7 @@ app.post('/transfer', async (c) => {
|
||||
receiver
|
||||
}
|
||||
|
||||
console.log('transfer', transfe);
|
||||
console.log('transfer', transfer);
|
||||
return c.json(transfer)
|
||||
})
|
||||
|
||||
|
||||
47
server.py
Normal file
47
server.py
Normal file
@ -0,0 +1,47 @@
|
||||
from flask import Flask, request, jsonify
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
accounts = {
|
||||
'1': {'amount': 1000},
|
||||
'2': {'amount': 1000},
|
||||
}
|
||||
|
||||
transactions = []
|
||||
|
||||
|
||||
# POST endpoint
|
||||
@app.route('/transfer', methods = ['POST'])
|
||||
def transfer():
|
||||
new_balance = request.get_json()
|
||||
from_account = new_balance.get('from_account')
|
||||
to_account = new_balance.get('to_account')
|
||||
desired_amount = new_balance.get('desired_amount')
|
||||
|
||||
# validate input
|
||||
if from from_account not in accounts or to_account not in accounts:
|
||||
return jsontify({"error: Invalid account"}), 404
|
||||
|
||||
# transfer process
|
||||
accounts[from_account]['amount'] -= desired_amount
|
||||
accounts[to_account]['amount'] += desired_amount
|
||||
transactions.append(accounts)
|
||||
|
||||
# GET endpoint
|
||||
@app.route ('/transfer', method=['GET'])
|
||||
def get_information():
|
||||
new_balance = request.get_json()
|
||||
from_account = new_balance.get('from_account')
|
||||
to_account = new_balance.get('to_account')
|
||||
|
||||
# validate input
|
||||
if from from_account not in accounts or to_account not in accounts:
|
||||
return jsontify({"error: Unknown account"}), 404
|
||||
|
||||
# get the information
|
||||
return jsontify(transactions)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user