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

View File

@ -1,2 +0,0 @@
node_modules/
build/

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +0,0 @@
{
"name": "money-transfer",
"version": "1.0.0",
"main": "server.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"dev": "node ./build/server.js",
"start": "tsc && npm run dev"
},
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/node": "^24.0.10",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
},
"dependencies": {
"cors": "^2.8.5",
"express": "^5.1.0"
}
}

View File

@ -1,18 +0,0 @@
import express, { Application } from "express";
import Server from "./src/index";
const app: Application = express();
const server: Server = new Server(app);
const PORT: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;
app
.listen(PORT, "localhost", function () {
console.log(`Server is running on port ${PORT}.`);
})
.on("error", (err: any) => {
if (err.code === "EADDRINUSE") {
console.log("Error: address already in use");
} else {
console.log(err);
}
});

View File

@ -1,18 +0,0 @@
import express, { Application } from "express";
import cors, { CorsOptions } from "cors";
export default class Server {
constructor(app: Application) {
this.config(app);
}
private config(app: Application): void {
const corsOptions: CorsOptions = {
origin: "http://localhost:8081"
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
}
}

View File

@ -1,25 +0,0 @@
{
"compilerOptions": {
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"resolveJsonModule": true, /* Enable importing .json files. */
/* Emit */
"outDir": "./build", /* Specify an output folder for all emitted files. */
/* Interop Constraints */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}

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}

View File

@ -10,7 +10,7 @@ const accounts = {
app.post('/transfer', async (c) => {
const body = await c.req.json();
const { amount, from, to } = body;
const { amount, sender, receiver } = body;
if (amount <= 0) {
return c.json({ error: 'Amount must be greater than 0' }, 40);
@ -18,8 +18,8 @@ app.post('/transfer', async (c) => {
const transfer = {
amount,
from,
to
sender,
receiver
}
console.log('transfer', transfe);