add python project and remove express projec
This commit is contained in:
2
express-js/.gitignore
vendored
2
express-js/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
node_modules/
|
|
||||||
build/
|
|
||||||
1180
express-js/package-lock.json
generated
1180
express-js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@ -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 }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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
1
fastapi-python/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
||||||
6
fastapi-python/README.md
Normal file
6
fastapi-python/README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Get started
|
||||||
|
|
||||||
|
```sh
|
||||||
|
|
||||||
|
fastapi dev main.py
|
||||||
|
```
|
||||||
29
fastapi-python/main.py
Normal file
29
fastapi-python/main.py
Normal 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}
|
||||||
@ -10,7 +10,7 @@ const accounts = {
|
|||||||
|
|
||||||
app.post('/transfer', async (c) => {
|
app.post('/transfer', async (c) => {
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
const { amount, from, to } = body;
|
const { amount, sender, receiver } = body;
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return c.json({ error: 'Amount must be greater than 0' }, 40);
|
return c.json({ error: 'Amount must be greater than 0' }, 40);
|
||||||
@ -18,8 +18,8 @@ app.post('/transfer', async (c) => {
|
|||||||
|
|
||||||
const transfer = {
|
const transfer = {
|
||||||
amount,
|
amount,
|
||||||
from,
|
sender,
|
||||||
to
|
receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('transfer', transfe);
|
console.log('transfer', transfe);
|
||||||
|
|||||||
Reference in New Issue
Block a user