34 lines
670 B
Python
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}
|