Compare commits
1 Commits
main
...
2025-07-16
| Author | SHA1 | Date | |
|---|---|---|---|
| ad99243944 |
@ -11,8 +11,8 @@ class Transfer(BaseModel):
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
accounts = {
|
accounts = {
|
||||||
'1': {'amount': 1000},
|
'1': 1000,
|
||||||
'2': {'amount': 1000},
|
'2': 1000,
|
||||||
}
|
}
|
||||||
|
|
||||||
transactions: list[Transfer] = []
|
transactions: list[Transfer] = []
|
||||||
@ -21,11 +21,32 @@ transactions: list[Transfer] = []
|
|||||||
def transfer(transfer: Transfer):
|
def transfer(transfer: Transfer):
|
||||||
amount = transfer.amount
|
amount = transfer.amount
|
||||||
sender = transfer.sender
|
sender = transfer.sender
|
||||||
receiver = transfer.receive
|
receiver = transfer.receiver
|
||||||
|
|
||||||
if amount <= 0:
|
if amount <= 0:
|
||||||
return {"error": "Amount must be greater than 0"}
|
return {"error": "Amount must be greater than 0"}
|
||||||
|
|
||||||
|
if accounts.get(sender) <= amount:
|
||||||
|
return {"error": "Sender does not have sufficient funds. "}
|
||||||
|
else:
|
||||||
|
# Minus sender's amount
|
||||||
|
accounts[sender] = accounts.get(sender) - amount
|
||||||
|
|
||||||
|
# Add receiver amount
|
||||||
|
accounts[receiver] = accounts.get(receiver) + amount
|
||||||
|
|
||||||
|
# Include the transaction
|
||||||
|
transactions.append(transfer)
|
||||||
|
|
||||||
print(f"transfer {amount} from {sender} to {receiver}")
|
print(f"transfer {amount} from {sender} to {receiver}")
|
||||||
|
print(transactions)
|
||||||
|
print(accounts.get("1"))
|
||||||
|
print(accounts.get("2"))
|
||||||
|
|
||||||
|
|
||||||
return {"amount": amount, "sender": sender, "receiver": receiver}
|
return {"amount": amount, "sender": sender, "receiver": receiver}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/transactions")
|
||||||
|
def getTransactions():
|
||||||
|
return transactions
|
||||||
|
|||||||
Reference in New Issue
Block a user