Files
2025-07-16 14:27:46 +08:00

34 lines
670 B
Python

from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
class Transfer(BaseModel):
amount: int
sender: str
receiver: str
app = FastAPI()
accounts = {
'1': {'amount': 1000},
'2': {'amount': 1000},
}
transactions: list[Transfer] = []
@app.post("/transfer")
def transfer(transfer: Transfer):
amount = transfer.amount
sender = transfer.sender
receiver = transfer.receive
if amount <= 0:
return {"error": "Amount must be greater than 0"}
# IMPLEMENTATION
print(f"transfer {amount} from {sender} to {receiver}")
return {"amount": amount, "sender": sender, "receiver": receiver}