feat: Semaine 8

This commit is contained in:
gauvainboiche
2026-05-11 09:25:19 +02:00
parent 606e43e53f
commit 3315cb2336
123 changed files with 5748 additions and 0 deletions
@@ -0,0 +1,9 @@
FROM python:3.12-slim
WORKDIR /app
RUN pip install fastapi uvicorn httpx
COPY main.py .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
+35
View File
@@ -0,0 +1,35 @@
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
app = FastAPI()
users_db = {}
next_id = 1
# DTO : Data Transfer Object
class CreateUserDTO(BaseModel):
name: str
email: str
@app.post("/users")
async def create_user(json: CreateUserDTO):
global next_id
user_id = next_id
next_id += 1
users_db[user_id] = {
"id": user_id,
"name": json.name,
"email": json.email
}
return users_db[user_id]
@app.get("/users/{user_id}")
async def get_user(user_id: int):
user = users_db.get(user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user
@app.get("/health")
def health():
return {"status": "ok", "service": "user-service"}