add python project and remove express projec

This commit is contained in:
2025-07-08 03:41:20 +08:00
parent f6394ea3c0
commit e5dd781966
10 changed files with 39 additions and 1271 deletions

1
fastapi-python/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

6
fastapi-python/README.md Normal file
View File

@ -0,0 +1,6 @@
# Get started
```sh
fastapi dev main.py
```

29
fastapi-python/main.py Normal file
View File

@ -0,0 +1,29 @@
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
class Transfer(BaseModel):
amount: int
sender: int
receiver: int
app = FastAPI()
accounts = {
'1': {'amount': 1000},
'2': {'amount': 1000},
}
@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"}
print(f"transfer {amount} from {sender} to {receiver}")
return {"amount": amount, "sender": sender, "receiver": receiver}