generated from vincent/template-projet
Backend (FastAPI + SQLAlchemy): - Modèles : User, Client, Audit, Cible, Vulnérabilité, Action - Auth JWT (register/login/me) avec bcrypt - Routes CRUD complets : clients, audits, cibles, vulnérabilités, actions - Schémas Pydantic v2, migrations Alembic configurées - Rate limiting (slowapi), CORS, structure scanners/reports pour phase 2 Frontend (Next.js 14 App Router): - shadcn/ui : Button, Input, Card, Badge, Label - Page login avec gestion token JWT - Dashboard avec stats temps réel - Pages Clients (grille) et Audits (liste) avec recherche - Layout avec sidebar navigation + protection auth - Dockerfiles multi-stage (backend + frontend standalone) Infrastructure: - docker-compose.yml : postgres, redis, backend, frontend - docker-compose.prod.yml avec labels Traefik - .env.example complet - .gitignore mis à jour Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from backend.core.database import get_db
|
|
from backend.core.security import get_current_user
|
|
from backend.models.client import Client
|
|
from backend.models.user import User
|
|
from backend.schemas.client import ClientCreate, ClientUpdate, ClientRead
|
|
|
|
router = APIRouter(prefix="/clients", tags=["clients"])
|
|
|
|
|
|
@router.get("/", response_model=list[ClientRead])
|
|
def list_clients(
|
|
skip: int = 0,
|
|
limit: int = 50,
|
|
db: Session = Depends(get_db),
|
|
_: User = Depends(get_current_user),
|
|
) -> list[Client]:
|
|
return db.query(Client).offset(skip).limit(limit).all()
|
|
|
|
|
|
@router.post("/", response_model=ClientRead, status_code=status.HTTP_201_CREATED)
|
|
def create_client(
|
|
payload: ClientCreate,
|
|
db: Session = Depends(get_db),
|
|
_: User = Depends(get_current_user),
|
|
) -> Client:
|
|
client = Client(**payload.model_dump())
|
|
db.add(client)
|
|
db.commit()
|
|
db.refresh(client)
|
|
return client
|
|
|
|
|
|
@router.get("/{client_id}", response_model=ClientRead)
|
|
def get_client(
|
|
client_id: int,
|
|
db: Session = Depends(get_db),
|
|
_: User = Depends(get_current_user),
|
|
) -> Client:
|
|
client = db.get(Client, client_id)
|
|
if not client:
|
|
raise HTTPException(status_code=404, detail="Client introuvable")
|
|
return client
|
|
|
|
|
|
@router.patch("/{client_id}", response_model=ClientRead)
|
|
def update_client(
|
|
client_id: int,
|
|
payload: ClientUpdate,
|
|
db: Session = Depends(get_db),
|
|
_: User = Depends(get_current_user),
|
|
) -> Client:
|
|
client = db.get(Client, client_id)
|
|
if not client:
|
|
raise HTTPException(status_code=404, detail="Client introuvable")
|
|
|
|
for field, value in payload.model_dump(exclude_unset=True).items():
|
|
setattr(client, field, value)
|
|
|
|
db.commit()
|
|
db.refresh(client)
|
|
return client
|
|
|
|
|
|
@router.delete("/{client_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
def delete_client(
|
|
client_id: int,
|
|
db: Session = Depends(get_db),
|
|
_: User = Depends(get_current_user),
|
|
) -> None:
|
|
client = db.get(Client, client_id)
|
|
if not client:
|
|
raise HTTPException(status_code=404, detail="Client introuvable")
|
|
db.delete(client)
|
|
db.commit()
|